Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Unexpected behavior filtering valor objects with list comprehensions #571

Closed
1 task done
jyono opened this issue Apr 30, 2024 · 3 comments
Closed
1 task done
Assignees

Comments

@jyono
Copy link
Contributor

jyono commented Apr 30, 2024

valor version checks

  • I have confirmed this bug exists on the latest version of valor.

Reproducible Example

from valor import connect, Client, Dataset, Model, Datum, Annotation, GroundTruth, Prediction, Label
from valor.schemas import Box
from valor.enums import TaskType

connect("https://valor.striveworks.com/api/v1", username=..., password=...)
client = Client()

pscope_test_dataset = Dataset.get("PlanetScope 1.2 Test")

sample_gt = pscope_test_dataset.get_groundtruth('')
sample_annotations = sample_gt.annotations
sample_labels = sample_annotations[0].labels

print(f"sample_labels = {sample_labels}")
print(f"sample_labels[0].value == 'some' => {sample_labels[0].value == 'some'}")
print(f"sample_labels[0].value == 'thing' => {sample_labels[0].value == 'thing'}")
print(f"[label for label in sample_labels if label.value == 'some'] = {[label for label in sample_labels if label.value == 'some']}")
print(f"[label for label in sample_labels if str(label.value) == 'some'] = {[label for label in sample_labels if str(label.value) == 'some']}")

Issue Description

I am getting unexpected behavior when filtering valor objects with list comprehensions, specifically that the filtering does not work unless I apply “str()” to the value to filter on. The following code snippet demonstrates the issue (“username” and “password” need to be provided to the connect() call):

from valor import connect, Client, Dataset, Model, Datum, Annotation, GroundTruth, Prediction, Label
from valor.schemas import Box
from valor.enums import TaskType

connect("https://valor.striveworks.com/api/v1", username=..., password=...)
client = Client()

pscope_test_dataset = Dataset.get("PlanetScope 1.2 Test")

sample_gt = pscope_test_dataset.get_groundtruth('')
sample_annotations = sample_gt.annotations
sample_labels = sample_annotations[0].labels

print(f"sample_labels = {sample_labels}")
print(f"sample_labels[0].value == 'some' => {sample_labels[0].value == 'some'}")
print(f"sample_labels[0].value == 'thing' => {sample_labels[0].value == 'thing'}")
print(f"[label for label in sample_labels if label.value == 'some'] = {[label for label in sample_labels if label.value == 'some']}")
print(f"[label for label in sample_labels if str(label.value) == 'some'] = {[label for label in sample_labels if str(label.value) == 'some']}")

output

sample_labels = [{'key': 'class_label', 'value': 'thing', 'score': None}]
sample_labels[0].value == 'some' => False
sample_labels[0].value == 'thing' => True
[label for label in sample_labels if label.value == 'some'] = [{'key': 'class_label', 'value': 'thing', 'score': None}]
[label for label in sample_labels if str(label.value) == 'some'] = []

Lines 2 and 3 here show that the value equality returns as expected, but line 4 shows it does not work as part of a list comprehension. Here, I would have expected the returned list to be empty, or an exception to be thrown if the two values were not comparable due to type mismatch. Line 5 shows that the list comprehension will work if str() is applied to the value.

Expected Behavior

expect it to work.

@jyono
Copy link
Contributor Author

jyono commented Apr 30, 2024

I created this on behalf of @MattMcClainStrive , please contact them for additional detail

@ntlind
Copy link
Collaborator

ntlind commented May 6, 2024

Eric is starting #572 to address this issue

@ekorman
Copy link
Contributor

ekorman commented May 14, 2024

closed with #572

@ekorman ekorman closed this as completed May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants