Striveworks / valor

Valor is a centralized evaluation store which makes it easy to measure, explore, and rank model performance.
https://striveworks.github.io/valor/
Other
37 stars 2 forks source link

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

Closed jyono closed 2 months ago

jyono commented 2 months ago

valor version checks

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 commented 2 months ago

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

ntlind commented 2 months ago

Eric is starting #572 to address this issue

ekorman commented 2 months ago

closed with #572