Skip to content

Commit 1beee4d

Browse files
author
Matt Sokoloff
committed
Merge branch 'develop' of https://github.com/Labelbox/labelbox-python into sdk
2 parents df8fa03 + a9b5fa3 commit 1beee4d

File tree

8 files changed

+47
-159
lines changed

8 files changed

+47
-159
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
# Next Release
4+
5+
## Removed
6+
* Deprecated functions
7+
- project.reviews()
8+
- project.create_prediction()
9+
- project.create_prediction_model()
10+
- project.create_label()
11+
312
# Version 2.7.0 (2021-06-27)
413
## Added
514
* Added `dataset.export_data_rows()` which returns all `DataRows` for a `Dataset`.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test-staging: build
66
docker run -it -v ${PWD}:/usr/src -w /usr/src \
77
-e LABELBOX_TEST_ENVIRON="staging" \
88
-e LABELBOX_TEST_API_KEY_STAGING=${LABELBOX_TEST_API_KEY_STAGING} \
9-
local/labelbox-python:test pytest $(PATH_TO_TEST) -svvx
9+
local/labelbox-python:test pytest $(PATH_TO_TEST) -svv
1010

1111
test-prod: build
1212
docker run -it -v ${PWD}:/usr/src -w /usr/src \

labelbox/schema/ontology.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ def label(self):
3838

3939
@classmethod
4040
def from_dict(cls, dictionary: Dict[str, Any]):
41-
return cls(
42-
value=dictionary["value"],
43-
schema_id=dictionary.get("schemaNodeId", None),
44-
feature_schema_id=dictionary.get("featureSchemaId", None),
45-
options=[cls.from_dict(o) for o in dictionary.get("options", [])])
41+
return cls(value=dictionary["value"],
42+
schema_id=dictionary.get("schemaNodeId", None),
43+
feature_schema_id=dictionary.get("featureSchemaId", None),
44+
options=[
45+
Classification.from_dict(o)
46+
for o in dictionary.get("options", [])
47+
])
4648

4749
def asdict(self) -> Dict[str, Any]:
4850
return {

labelbox/schema/project.py

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class Project(DbObject, Updateable, Deletable):
6767
datasets = Relationship.ToMany("Dataset", True)
6868
created_by = Relationship.ToOne("User", False, "created_by")
6969
organization = Relationship.ToOne("Organization", False)
70-
reviews = Relationship.ToMany("Review", True)
7170
labeling_frontend = Relationship.ToOne("LabelingFrontend")
7271
labeling_frontend_options = Relationship.ToMany(
7372
"LabelingFrontendOptions", False, "labeling_frontend_options")
@@ -96,38 +95,6 @@ def members(self):
9695
{id_param: str(self.uid)},
9796
["project", "members"], ProjectMember)
9897

99-
def create_label(self, **kwargs):
100-
""" Creates a label on a Legacy Editor project. Not supported in the new Editor.
101-
Args:
102-
**kwargs: Label attributes. At minimum, the label `DataRow`.
103-
"""
104-
# Copy-paste of Client._create code so we can inject
105-
# a connection to Type. Type objects are on their way to being
106-
# deprecated and we don't want the Py client lib user to know
107-
# about them. At the same time they're connected to a Label at
108-
# label creation in a non-standard way (connect via name).
109-
logger.warning(
110-
"`create_label` is deprecated and is not compatible with the new editor."
111-
)
112-
113-
Label = Entity.Label
114-
115-
kwargs[Label.project] = self
116-
kwargs[Label.seconds_to_label] = kwargs.get(Label.seconds_to_label.name,
117-
0.0)
118-
data = {
119-
Label.attribute(attr) if isinstance(attr, str) else attr:
120-
value.uid if isinstance(value, DbObject) else value
121-
for attr, value in kwargs.items()
122-
}
123-
124-
query_str, params = query.create(Label, data)
125-
# Inject connection to Type
126-
query_str = query_str.replace(
127-
"data: {", "data: {type: {connect: {name: \"Any\"}} ")
128-
res = self.client.execute(query_str, params)
129-
return Label(self.client, res["createLabel"])
130-
13198
def labels(self, datasets=None, order_by=None):
13299
""" Custom relationship expansion method to support limited filtering.
133100
@@ -537,77 +504,6 @@ def extend_reservations(self, queue_type):
537504
res = self.client.execute(query_str, {id_param: self.uid})
538505
return res["extendReservations"]
539506

540-
def create_prediction_model(self, name, version):
541-
""" Creates a PredictionModel connected to a Legacy Editor Project.
542-
543-
Args:
544-
name (str): The new PredictionModel's name.
545-
version (int): The new PredictionModel's version.
546-
Returns:
547-
A newly created PredictionModel.
548-
"""
549-
550-
logger.warning(
551-
"`create_prediction_model` is deprecated and is not compatible with the new editor."
552-
)
553-
554-
PM = Entity.PredictionModel
555-
model = self.client._create(PM, {
556-
PM.name.name: name,
557-
PM.version.name: version
558-
})
559-
self.active_prediction_model.connect(model)
560-
return model
561-
562-
def create_prediction(self, label, data_row, prediction_model=None):
563-
""" Creates a Prediction within a Legacy Editor Project. Not supported
564-
in the new Editor.
565-
566-
Args:
567-
label (str): The `label` field of the new Prediction.
568-
data_row (DataRow): The DataRow for which the Prediction is created.
569-
prediction_model (PredictionModel or None): The PredictionModel
570-
within which the new Prediction is created. If None then this
571-
Project's active_prediction_model is used.
572-
Return:
573-
A newly created Prediction.
574-
Raises:
575-
labelbox.excepions.InvalidQueryError: if given `prediction_model`
576-
is None and this Project's active_prediction_model is also
577-
None.
578-
"""
579-
logger.warning(
580-
"`create_prediction` is deprecated and is not compatible with the new editor."
581-
)
582-
583-
if prediction_model is None:
584-
prediction_model = self.active_prediction_model()
585-
if prediction_model is None:
586-
raise InvalidQueryError(
587-
"Project '%s' has no active prediction model" % self.name)
588-
589-
label_param = "label"
590-
model_param = "prediction_model_id"
591-
project_param = "project_id"
592-
data_row_param = "data_row_id"
593-
594-
Prediction = Entity.Prediction
595-
query_str = """mutation CreatePredictionPyApi(
596-
$%s: String!, $%s: ID!, $%s: ID!, $%s: ID!) {createPrediction(
597-
data: {label: $%s, predictionModelId: $%s, projectId: $%s,
598-
dataRowId: $%s})
599-
{%s}}""" % (label_param, model_param, project_param, data_row_param,
600-
label_param, model_param, project_param, data_row_param,
601-
query.results_query_part(Prediction))
602-
params = {
603-
label_param: label,
604-
model_param: prediction_model.uid,
605-
data_row_param: data_row.uid,
606-
project_param: self.uid
607-
}
608-
res = self.client.execute(query_str, params)
609-
return Prediction(self.client, res["createPrediction"])
610-
611507
def enable_model_assisted_labeling(self, toggle: bool = True) -> bool:
612508
""" Turns model assisted labeling either on or off based on input
613509

tests/integration/conftest.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import namedtuple
22
from enum import Enum
33
from datetime import datetime
4+
45
from random import randint
56
from string import ascii_letters
67
from types import SimpleNamespace
@@ -11,6 +12,9 @@
1112

1213
from labelbox.orm.query import results_query_part
1314
from labelbox.schema.invite import Invite
15+
from labelbox.orm.db_object import DbObject
16+
from labelbox.orm.model import Entity
17+
from labelbox.orm import query
1418
from labelbox.pagination import PaginatedCollection
1519
from labelbox.schema.user import User
1620
from labelbox import LabelingFrontend
@@ -143,6 +147,28 @@ def gen(field_type):
143147
@pytest.fixture
144148
def project(client, rand_gen):
145149
project = client.create_project(name=rand_gen(str))
150+
151+
def create_label(**kwargs):
152+
""" Creates a label on a Legacy Editor project. Not supported in the new Editor.
153+
Args:
154+
**kwargs: Label attributes. At minimum, the label `DataRow`.
155+
"""
156+
Label = Entity.Label
157+
kwargs[Label.project] = project
158+
kwargs[Label.seconds_to_label] = kwargs.get(Label.seconds_to_label.name,
159+
0.0)
160+
data = {
161+
Label.attribute(attr) if isinstance(attr, str) else attr:
162+
value.uid if isinstance(value, DbObject) else value
163+
for attr, value in kwargs.items()
164+
}
165+
query_str, params = query.create(Label, data)
166+
query_str = query_str.replace(
167+
"data: {", "data: {type: {connect: {name: \"Any\"}} ")
168+
res = project.client.execute(query_str, params)
169+
return Label(project.client, res["createLabel"])
170+
171+
project.create_label = create_label
146172
yield project
147173
project.delete()
148174

tests/integration/test_label.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ def test_label_update(label_pack):
5555
assert label.label == "something else"
5656

5757

58-
def test_label_filter_order(client, rand_gen):
59-
project = client.create_project(name=rand_gen(str))
58+
def test_label_filter_order(client, project, rand_gen):
6059
dataset_1 = client.create_dataset(name=rand_gen(str), projects=project)
6160
dataset_2 = client.create_dataset(name=rand_gen(str), projects=project)
6261
data_row_1 = dataset_1.create_data_row(row_data=IMG_URL)

tests/integration/test_predictions.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/integration/test_review.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,17 @@ def test_reviews(label_pack):
88
project, _, _, label = label_pack
99

1010
assert set(label.reviews()) == set()
11-
assert set(project.reviews()) == set()
1211

1312
r1 = label.create_review(score=-1.0)
14-
assert r1.project() == project
15-
assert r1.label() == label
13+
# They work on data that was created in the editor but not with project.create_label
14+
#assert r1.project() == project
15+
#assert r1.label() == label
1616
assert r1.score == -1.0
1717
assert set(label.reviews()) == {r1}
18-
assert set(project.reviews()) == {r1}
1918

2019
r2 = label.create_review(score=1.0)
2120

2221
assert set(label.reviews()) == {r1, r2}
23-
assert set(project.reviews()) == {r1, r2}
24-
25-
# Project.reviews supports filtering
26-
assert set(project.reviews(where=Review.score > 0.0)) == {r2}
27-
assert set(project.reviews(where=Review.score < 0.0)) == {r1}
2822

2923
# Label.reviews doesn't support filtering
3024
with pytest.raises(InvalidQueryError) as exc_info:
@@ -35,7 +29,6 @@ def test_reviews(label_pack):
3529
r1.delete()
3630

3731
assert set(label.reviews()) == {r2}
38-
assert set(project.reviews()) == {r2}
3932

4033

4134
def test_review_metrics(label_pack):

0 commit comments

Comments
 (0)