Skip to content

Commit 1fd1d57

Browse files
committed
MODEL-1448: Fixed formatting, switched to pydantic class approach
1 parent 8d5b97c commit 1fd1d57

File tree

4 files changed

+46
-27
lines changed

4 files changed

+46
-27
lines changed

libs/labelbox/src/labelbox/client.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,19 +2218,41 @@ def get_embedding_by_name(self, name: str) -> Embedding:
22182218
dict(name=name))
22192219

22202220
def upsert_label_feedback(self, label_id: str, feedback: str,
2221-
scores: Dict[str, float]) -> Entity.Label:
2221+
scores: Dict[str, float]) -> List[Entity.Label]:
22222222
"""
2223+
Submits the label feedback which is a free-form text and numeric
2224+
label scores.
22232225
22242226
Args:
22252227
label_id: Target label ID
22262228
feedback: Free text comment regarding the label
2227-
scores: A dict of scores, the key is a score name and the value is the score value
2228-
Returns: A list of LabelScore instances
2229+
scores: A dict of scores, the key is a score name and the value is
2230+
the score value
22292231
2230-
"""
2231-
mutation_str = """mutation UpsertAutoQaLabelFeedbackPyApi($labelId: ID!, $feedback: String!, $scores: Json!){
2232-
upsertAutoQaLabelFeedback(input: {labelId: $labelId, feedback: $feedback, scores: $scores}) { id scores {id name score} }
2233-
}
2232+
Returns:
2233+
A list of LabelScore instances
2234+
"""
2235+
mutation_str = """
2236+
mutation UpsertAutoQaLabelFeedbackPyApi(
2237+
$labelId: ID!
2238+
$feedback: String!
2239+
$scores: Json!
2240+
) {
2241+
upsertAutoQaLabelFeedback(
2242+
input: {
2243+
labelId: $labelId,
2244+
feedback: $feedback,
2245+
scores: $scores
2246+
}
2247+
) {
2248+
id
2249+
scores {
2250+
id
2251+
name
2252+
score
2253+
}
2254+
}
2255+
}
22342256
"""
22352257
res = self.execute(mutation_str, {
22362258
"labelId": label_id,
@@ -2239,4 +2261,7 @@ def upsert_label_feedback(self, label_id: str, feedback: str,
22392261
})
22402262
scores_raw = res["upsertAutoQaLabelFeedback"]["scores"]
22412263

2242-
return [Entity.LabelScore(self, x) for x in scores_raw]
2264+
return [
2265+
labelbox.LabelScore(name=x['name'], score=x['score'])
2266+
for x in scores_raw
2267+
]

libs/labelbox/src/labelbox/orm/model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ class Entity(metaclass=EntityMeta):
382382
CatalogSlice: Type[labelbox.CatalogSlice]
383383
ModelSlice: Type[labelbox.ModelSlice]
384384
TaskQueue: Type[labelbox.TaskQueue]
385-
LabelScore: Type[labelbox.LabelScore]
386385

387386
@classmethod
388387
def _attributes_of_type(cls, attr_type):
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
from labelbox.orm.db_object import DbObject
2-
from labelbox.orm.model import Field
1+
from labelbox import pydantic_compat
32

43

5-
class LabelScore(DbObject):
4+
class LabelScore(pydantic_compat.BaseModel):
65
"""
76
a label score
87
@@ -12,8 +11,5 @@ class LabelScore(DbObject):
1211
1312
"""
1413

15-
name = Field.String("name")
16-
data_row_count = Field.Float("score")
17-
18-
def __init__(self, client, *args, **kwargs):
19-
super().__init__(client, *args, **kwargs)
14+
name: str
15+
score: float

libs/labelbox/tests/integration/test_label.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import os
12
import time
23

3-
from labelbox import Client
44
import pytest
5-
import os
65

7-
from labelbox import Label
6+
from labelbox import Client, Label
87

98

109
def test_labels(configured_project_with_label):
@@ -30,10 +29,10 @@ def test_labels(configured_project_with_label):
3029

3130
# TODO: Skipping this test in staging due to label not updating
3231
@pytest.mark.skipif(
33-
condition=os.environ["LABELBOX_TEST_ENVIRON"] == "onprem"
34-
or os.environ["LABELBOX_TEST_ENVIRON"] == "staging"
35-
or os.environ["LABELBOX_TEST_ENVIRON"] == "local"
36-
or os.environ["LABELBOX_TEST_ENVIRON"] == "custom",
32+
condition=os.environ["LABELBOX_TEST_ENVIRON"] == "onprem" or
33+
os.environ["LABELBOX_TEST_ENVIRON"] == "staging" or
34+
os.environ["LABELBOX_TEST_ENVIRON"] == "local" or
35+
os.environ["LABELBOX_TEST_ENVIRON"] == "custom",
3736
reason="does not work for onprem",
3837
)
3938
def test_label_update(configured_project_with_label):
@@ -83,8 +82,8 @@ def test_upsert_label_scores(configured_project_with_label, client: Client):
8382

8483
label = next(project.labels())
8584

86-
scores = client.upsert_label_feedback(
87-
label_id=label.uid, feedback="That's a great label!", scores={"overall": 5}
88-
)
85+
scores = client.upsert_label_feedback(label_id=label.uid,
86+
feedback="That's a great label!",
87+
scores={"overall": 5})
8988
assert len(scores) == 1
9089
assert scores[0].score == 5

0 commit comments

Comments
 (0)