Skip to content

Commit 88f81cc

Browse files
author
Val Brodsky
committed
Update docstring and Add a deprecation warning
1 parent 36f4a23 commit 88f81cc

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

labelbox/data/annotation_types/data/generic_data_row_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
class GenericDataRowData(BaseData, _NoCoercionMixin):
9-
"""Generic data row data
9+
"""Generic data row data. This is replacing all other DataType passed into Label
1010
"""
1111
url: Optional[str] = None
1212
class_name: Literal["GenericDataRowData"] = "GenericDataRowData"

labelbox/data/annotation_types/label.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Label(pydantic_compat.BaseModel):
2929
"""Container for holding data and annotations
3030
3131
>>> Label(
32-
>>> data = ImageData(url = "http://my-img.jpg"),
32+
>>> data = {'global_key': 'my-data-row-key'} # also accepts uid, external_id as keys
3333
>>> annotations = [
3434
>>> ObjectAnnotation(
3535
>>> value = Point(x = 10, y = 10),
@@ -40,7 +40,8 @@ class Label(pydantic_compat.BaseModel):
4040
4141
Args:
4242
uid: Optional Label Id in Labelbox
43-
data: Data of Label, Image, Video, Text
43+
data: Data of Label, Image, Video, Text or dict with a single key uid | global_key | external_id.
44+
Note use of classes as data is deprecated. Use GenericDataRowData or dict with a single key instead.
4445
annotations: List of Annotations in the label
4546
extra: additional context
4647
"""
@@ -62,6 +63,10 @@ def is_data_type(data: Union[Dict[str, Any], DataType]) -> bool:
6263
def validate_data(cls, label):
6364
if not Label.is_data_type(label.get("data")):
6465
label["data"]["class_name"] = "GenericDataRowData"
66+
else:
67+
warnings.warn(
68+
f"Using {type(label['data']).__name__} class for label.data is deprecated. "
69+
"Use a dict or an instance of GenericDataRowData instead.")
6570
return label
6671

6772
def object_annotations(self) -> List[ObjectAnnotation]:

tests/unit/test_label_data_type.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def test_video_data_type():
4141
'global_key':
4242
'https://lb-test-data.s3.us-west-1.amazonaws.com/image-samples/sample-image-1.jpg-BEidMVWRmyXjVCnr',
4343
}
44-
label = Label(data=VideoData(**data))
44+
with pytest.warns(UserWarning, match="Use a dict"):
45+
label = Label(data=VideoData(**data))
4546
data = label.data
4647
assert isinstance(data, VideoData)
4748
assert data.global_key == 'https://lb-test-data.s3.us-west-1.amazonaws.com/image-samples/sample-image-1.jpg-BEidMVWRmyXjVCnr'

0 commit comments

Comments
 (0)