Skip to content

Commit 272e149

Browse files
author
Matt Sokoloff
committed
create data row from objects
1 parent 22b97bd commit 272e149

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

labelbox/orm/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ def DateTime(*args):
104104
return Field(Field.Type.DateTime, *args)
105105

106106
@staticmethod
107-
def Enum(enum_cls: type, *args):
108-
return Field(Field.EnumType(enum_cls), *args)
107+
def Enum(enum_cls: type, *args, **kwargs):
108+
return Field(Field.EnumType(enum_cls), *args, **kwargs)
109109

110110
@staticmethod
111111
def Json(*args):

labelbox/schema/data_row.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from labelbox.orm.db_object import DbObject, Updateable, BulkDeletable
66
from labelbox.orm.model import Entity, Field, Relationship
77
from labelbox.schema.data_row_metadata import DataRowMetadataField # type: ignore
8+
from labelbox.schema.media_type import MediaType
89

910
if TYPE_CHECKING:
1011
from labelbox import AssetAttachment
@@ -48,6 +49,7 @@ class DataRow(DbObject, Updateable, BulkDeletable):
4849
name="metadata",
4950
graphql_name="customMetadata",
5051
result_subquery="customMetadata { schemaId value }")
52+
media_type = Field.Enum(MediaType, "media_type", result_subquery="")
5153

5254
# Relationships
5355
dataset = Relationship.ToOne("Dataset")
@@ -59,8 +61,9 @@ class DataRow(DbObject, Updateable, BulkDeletable):
5961
supported_meta_types = supported_attachment_types = set(
6062
Entity.AssetAttachment.AttachmentType.__members__)
6163

62-
def __init__(self, *args, **kwargs):
63-
super().__init__(*args, **kwargs)
64+
def __init__(self, client, field_values, **kwargs):
65+
field_values.update({'mediaType': MediaType.Unknown})
66+
super().__init__(client, field_values, **kwargs)
6467
self.attachments.supports_filtering = False
6568
self.attachments.supports_sorting = False
6669

labelbox/schema/dataset.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,12 @@ def convert_field_keys(items):
9595
raise InvalidQueryError(
9696
"DataRow.row_data missing when creating DataRow.")
9797

98-
# If row data is a local file path, upload it to server.
9998
row_data = args[DataRow.row_data.name]
100-
if os.path.exists(row_data):
99+
if not isinstance(row_data, str):
100+
# If the row data is an object, upload as a string
101+
args[DataRow.row_data.name] = json.dumps(row_data)
102+
elif os.path.exists(row_data):
103+
# If row data is a local file path, upload it to server.
101104
args[DataRow.row_data.name] = self.client.upload_file(row_data)
102105
args[DataRow.dataset.name] = self
103106

@@ -106,6 +109,7 @@ def convert_field_keys(items):
106109
mdo = self.client.get_data_row_metadata_ontology()
107110
args[DataRow.metadata_fields.name] = mdo.parse_upsert_metadata(
108111
args[DataRow.metadata_fields.name])
112+
109113
return self.client._create(DataRow, args)
110114

111115
def create_data_rows_sync(self, items) -> None:

labelbox/schema/media_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class MediaType(Enum):
2121

2222
@classmethod
2323
def _missing_(cls, name):
24-
"""Handle missing null data types for projects
24+
"""Handle missing null data types for projects
2525
created without setting allowedMediaType
26-
Handle upper case names for compatibility with
26+
Handle upper case names for compatibility with
2727
the GraphQL"""
2828

2929
if name is None:

0 commit comments

Comments
 (0)