Skip to content

Commit d841ef4

Browse files
committed
override dicts
1 parent 09b5d45 commit d841ef4

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

labelbox/data/annotation_types/feature.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ def must_set_one(cls, values):
2424
"Must set either feature_schema_id or name for all feature schemas"
2525
)
2626
return values
27+
28+
def dict(self, *args, **kwargs):
29+
res = super().dict(*args, **kwargs)
30+
if res.name is None:
31+
res.pop('name')
32+
if res.feature_schema_id is None:
33+
res.pop('feature_schema_id')
34+
return res

labelbox/data/serialization/ndjson/base.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ def validate_id(cls, v, values):
4747
raise ValueError(
4848
"Schema ids or names are not set. Use `LabelGenerator.assign_feature_schema_ids`, `LabelList.assign_feature_schema_ids`, or `Label.assign_feature_schema_ids`."
4949
)
50-
return v
50+
return v
51+
52+
def dict(self, *args, **kwargs):
53+
res = super().dict(*args, **kwargs)
54+
if res.name is None:
55+
res.pop('name')
56+
if res.schema_id is None:
57+
res.pop('schema_id')
58+
return res

labelbox/data/serialization/ndjson/classification.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ def validate_id(cls, v, values):
2727
)
2828
return v
2929

30+
def dict(self, *args, **kwargs):
31+
res = super().dict(*args, **kwargs)
32+
if res.name is None:
33+
res.pop('name')
34+
if res.schema_id is None:
35+
res.pop('schema_id')
36+
return res
37+
3038
class Config:
3139
allow_population_by_field_name = True
3240
alias_generator = camel_case

labelbox/data/serialization/ndjson/converter.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,4 @@ def serialize(
3939
A generator for accessing the ndjson representation of the data
4040
"""
4141
for example in NDLabel.from_common(labels):
42-
res = example.dict(by_alias=True)
43-
if res.schema_id is None:
44-
res.pop('schema_id')
45-
if res.name is None:
46-
res.pop('name')
47-
yield res
42+
yield example.dict(by_alias=True)

0 commit comments

Comments
 (0)