Skip to content

Commit 9170913

Browse files
authored
Merge pull request #218 from Labelbox/ms/datarow-metadata-updates
datarow metadata updates
2 parents f609801 + 2d4e59f commit 9170913

18 files changed

+827
-169
lines changed

CONTRIB.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,20 @@ following packages/modules:
2727

2828
## Testing
2929

30-
Currently the SDK functionality is tested using integration tests. These tests
30+
Currently, the SDK functionality is tested using integration tests. These tests
3131
communicate with a Labelbox server (by default the staging server) and are in
32-
that sense not self-contained. Besides that they are organized like unit test
32+
that sense not self-contained. Besides, that they are organized like unit test
3333
and are based on the `pytest` library.
3434

3535
To execute tests you will need to provide an API key for the server you're using
3636
for testing (staging by default) in the `LABELBOX_TEST_API_KEY` environment
37-
variable. For more info see [Labelbox API key
38-
docs](https://labelbox.helpdocs.io/docs/api/getting-started).
37+
variable. For more info see [Labelbox API key docs](https://labelbox.helpdocs.io/docs/api/getting-started).
38+
39+
To pass tests, code must be formatted using the following command:
40+
41+
```shell
42+
yapf labelbox -i --verbose --recursive --parallel --style "google"
43+
```
3944

4045
## Release Steps
4146

@@ -47,10 +52,8 @@ Each release should follow the following steps:
4752
4. Merge `develop` to `master` (fast-forward only).
4853
5. Create a GitHub release.
4954
6. This will kick off a Github Actions workflow that will:
50-
- Build the library in the [standard
51-
way](https://packaging.python.org/tutorials/packaging-projects/#generating-distribution-archives)
52-
- Upload the distribution archives in the [standard
53-
way](https://packaging.python.org/tutorials/packaging-projects/#uploading-the-distribution-archives)
55+
- Build the library in the [standard way](https://packaging.python.org/tutorials/packaging-projects/#generating-distribution-archives)
56+
- Upload the distribution archives in the [standard way](https://packaging.python.org/tutorials/packaging-projects/#uploading-the-distribution-archives)
5457
with credentials for the `labelbox` PyPI user.
5558
- Run the `REPO_ROOT/tools/api_reference_generator.py` script to update
5659
[HelpDocs documentation](https://labelbox.helpdocs.io/docs/). You will need

labelbox/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
from labelbox.schema.organization import Organization
1515
from labelbox.schema.task import Task
1616
from labelbox.schema.labeling_frontend import LabelingFrontend
17-
from labelbox.schema.asset_metadata import AssetMetadata
1817
from labelbox.schema.asset_attachment import AssetAttachment
1918
from labelbox.schema.webhook import Webhook
2019
from labelbox.schema.ontology import Ontology, OntologyBuilder, Classification, Option, Tool
2120
from labelbox.schema.role import Role, ProjectRole
2221
from labelbox.schema.invite import Invite, InviteLimit
22+
from labelbox.schema.data_row_metadata import DataRowMetadataOntology
2323
from labelbox.schema.model_run import ModelRun

labelbox/client.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# type: ignore
12
from datetime import datetime, timezone
23
import json
34
import logging
@@ -15,9 +16,11 @@
1516
from labelbox.pagination import PaginatedCollection
1617
from labelbox.schema.project import Project
1718
from labelbox.schema.dataset import Dataset
19+
from labelbox.schema.data_row import DataRow
1820
from labelbox.schema.model import Model
1921
from labelbox.schema.user import User
2022
from labelbox.schema.organization import Organization
23+
from labelbox.schema.data_row_metadata import DataRowMetadataOntology
2124
from labelbox.schema.labeling_frontend import LabelingFrontend
2225
from labelbox.schema import role
2326
from labelbox import __version__ as SDK_VERSION
@@ -45,7 +48,6 @@ def __init__(self,
4548
Logging is defaulted to level WARNING. To receive more verbose
4649
output to console, update `logging.level` to the appropriate level.
4750
48-
>>> import logger
4951
>>> logging.basicConfig(level = logging.INFO)
5052
>>> client = Client("<APIKEY>")
5153
@@ -541,6 +543,24 @@ def get_roles(self):
541543
"""
542544
return role.get_roles(self)
543545

546+
def get_data_row(self, data_row_id):
547+
"""
548+
549+
Returns:
550+
DataRow: returns a single data row given the data row id
551+
"""
552+
553+
return self._get_single(DataRow, data_row_id)
554+
555+
def get_data_row_metadata_ontology(self):
556+
"""
557+
558+
Returns:
559+
DataRowMetadataOntology: The ontology for Data Row Metadata for an organization
560+
561+
"""
562+
return DataRowMetadataOntology(self)
563+
544564
def get_model(self, model_id):
545565
""" Gets a single Model with the given ID.
546566

labelbox/schema/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import labelbox.schema.asset_metadata
21
import labelbox.schema.asset_attachment
32
import labelbox.schema.bulk_import_request
43
import labelbox.schema.annotation_import
@@ -18,3 +17,4 @@
1817
import labelbox.schema.task
1918
import labelbox.schema.user
2019
import labelbox.schema.webhook
20+
import labelbox.schema.data_row_metadata

labelbox/schema/asset_metadata.py

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

labelbox/schema/data_row.py

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import logging
2+
from datetime import datetime
3+
from typing import List, Dict, Union
24

35
from labelbox.orm import query
46
from labelbox.orm.db_object import DbObject, Updateable, BulkDeletable
@@ -18,6 +20,7 @@ class DataRow(DbObject, Updateable, BulkDeletable):
1820
updated_at (datetime)
1921
created_at (datetime)
2022
media_attributes (dict): generated media attributes for the datarow
23+
metadata (dict): uploaded metadata
2124
2225
dataset (Relationship): `ToOne` relationship to Dataset
2326
created_by (Relationship): `ToOne` relationship to User
@@ -37,21 +40,45 @@ class DataRow(DbObject, Updateable, BulkDeletable):
3740
created_by = Relationship.ToOne("User", False, "created_by")
3841
organization = Relationship.ToOne("Organization", False)
3942
labels = Relationship.ToMany("Label", True)
40-
41-
metadata = Relationship.ToMany(
42-
"AssetMetadata",
43-
False,
44-
"metadata",
45-
deprecation_warning=
46-
"`DataRow.metadata()` is deprecated. Use `DataRow.attachments()` instead."
47-
)
4843
attachments = Relationship.ToMany("AssetAttachment", False, "attachments")
4944

5045
supported_meta_types = supported_attachment_types = {
5146
attachment_type.value
5247
for attachment_type in AssetAttachment.AttachmentType
5348
}
5449

50+
def __init__(self, *args, **kwargs):
51+
super().__init__(*args, **kwargs)
52+
self.attachments.supports_filtering = False
53+
self.attachments.supports_sorting = False
54+
55+
@property
56+
def metadata(self) -> Dict[str, Union[str, List[Dict]]]:
57+
"""Get metadata for datarow
58+
"""
59+
60+
query = """query GetDataRowMetadataBetaPyApi($dataRowID: ID!) {
61+
dataRow(where: {id: $dataRowID}) {
62+
customMetadata {
63+
value
64+
schemaId
65+
}
66+
}
67+
}
68+
"""
69+
70+
metadata = self.client.execute(
71+
query, {"dataRowID": self.uid})["dataRow"]["customMetadata"]
72+
73+
return {
74+
"data_row_id":
75+
self.uid,
76+
"fields": [{
77+
"schema_id": m["schemaId"],
78+
"value": m["value"]
79+
} for m in metadata]
80+
}
81+
5582
@staticmethod
5683
def bulk_delete(data_rows):
5784
""" Deletes all the given DataRows.
@@ -61,13 +88,6 @@ def bulk_delete(data_rows):
6188
"""
6289
BulkDeletable._bulk_delete(data_rows, True)
6390

64-
def __init__(self, *args, **kwargs):
65-
super().__init__(*args, **kwargs)
66-
self.metadata.supports_filtering = False
67-
self.metadata.supports_sorting = False
68-
self.attachments.supports_filtering = False
69-
self.attachments.supports_sorting = False
70-
7191
def create_attachment(self, attachment_type, attachment_value):
7292
""" Adds an AssetAttachment to a DataRow.
7393
Labelers can view these attachments while labeling.
@@ -108,21 +128,3 @@ def create_attachment(self, attachment_type, attachment_value):
108128
})
109129
return Entity.AssetAttachment(self.client,
110130
res["createDataRowAttachment"])
111-
112-
def create_metadata(self, meta_type, meta_value):
113-
"""
114-
115-
This function is deprecated. Use create_attachment instead
116-
117-
Returns:
118-
AssetMetadata
119-
"""
120-
logger.warning(
121-
"`create_metadata` is deprecated. Use `create_attachment` instead.")
122-
attachment = self.create_attachment(meta_type, meta_value)
123-
return Entity.AssetMetadata(
124-
self.client, {
125-
'id': attachment.uid,
126-
'metaType': attachment.attachment_type,
127-
'metaValue': attachment.attachment_value
128-
})

0 commit comments

Comments
 (0)