Skip to content

Commit 11cbafb

Browse files
author
gdj0nes
committed
FIX: docs and reserved by name construction
1 parent 7487c13 commit 11cbafb

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

examples/basics/data_row_metadata.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@
374374
" value=dt,\n",
375375
" ),\n",
376376
" DataRowMetadataField(\n",
377-
" schema_id=mdo.reserved_by_name[\"split\"].uid,\n",
378-
" value=split\n",
377+
" schema_id=split.parent,\n",
378+
" value=split.uid\n",
379379
" ),\n",
380380
" DataRowMetadataField(\n",
381381
" schema_id=mdo.reserved_by_name[\"tag\"].uid,\n",

labelbox/schema/data_row_metadata.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# type: ignore
22
import datetime
33
import warnings
4+
from copy import deepcopy
45
from enum import Enum
56
from itertools import chain
67
from typing import List, Optional, Dict, Union, Callable, Type, Any, Generator
@@ -150,7 +151,7 @@ def _make_name_index(fields: List[DataRowMetadataSchema]):
150151
if f.options:
151152
index[f.name] = {}
152153
for o in f.options:
153-
index[o.name] = o
154+
index[f.name][o.name] = o
154155
else:
155156
index[f.name] = f
156157
return index
@@ -187,13 +188,14 @@ def _get_ontology(self) -> List[Dict[str, Any]]:
187188
@staticmethod
188189
def _parse_ontology(raw_ontology) -> List[DataRowMetadataSchema]:
189190
fields = []
190-
for schema in raw_ontology:
191-
schema["uid"] = schema.pop("id")
191+
copy = deepcopy(raw_ontology)
192+
for schema in copy:
193+
schema["uid"] = schema["id"]
192194
options = None
193195
if schema.get("options"):
194196
options = []
195197
for option in schema["options"]:
196-
option["uid"] = option.pop("id")
198+
option["uid"] = option["id"]
197199
options.append(
198200
DataRowMetadataSchema(**{
199201
**option,

tests/integration/test_data_row_metadata.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
DataRowMetadataOntology
99

1010
FAKE_SCHEMA_ID = "0" * 25
11+
FAKE_DATAROW_ID = "D" * 25
1112
SPLIT_SCHEMA_ID = "cko8sbczn0002h2dkdaxb5kal"
1213
TRAIN_SPLIT_ID = "cko8sbscr0003h2dk04w86hof"
1314
TEST_SPLIT_ID = "cko8scbz70005h2dkastwhgqt"
@@ -22,24 +23,11 @@
2223
"reserved": False
2324
}
2425

25-
"""
26-
customMetadataOntology {
27-
id
28-
name
29-
kind
30-
reserved
31-
options {
32-
id
33-
kind
34-
name
35-
reserved
36-
}
37-
}}"""
38-
3926

4027
@pytest.fixture
4128
def mdo(client):
4229
mdo = client.get_data_row_metadata_ontology()
30+
mdo._raw_ontology = mdo._get_ontology()
4331
mdo._raw_ontology.append(FAKE_NUMBER_FIELD)
4432
mdo._build_ontology()
4533
yield mdo
@@ -91,7 +79,27 @@ def make_metadata(dr_id) -> DataRowMetadata:
9179
def test_get_datarow_metadata_ontology(mdo):
9280
assert len(mdo.fields)
9381
assert len(mdo.reserved_fields)
94-
assert len(mdo.custom_fields) == 0
82+
assert len(mdo.custom_fields) == 1
83+
84+
split = mdo.reserved_by_name["split"]["train"]
85+
86+
assert DataRowMetadata(
87+
data_row_id=FAKE_DATAROW_ID,
88+
fields=[
89+
DataRowMetadataField(
90+
schema_id=mdo.reserved_by_name["captureDateTime"].uid,
91+
value=datetime.utcnow(),
92+
),
93+
DataRowMetadataField(
94+
schema_id=split.parent,
95+
value=split.uid
96+
),
97+
DataRowMetadataField(
98+
schema_id=mdo.reserved_by_name["tag"].uid,
99+
value="hello-world"
100+
),
101+
]
102+
)
95103

96104

97105
def test_bulk_upsert_datarow_metadata(datarow, mdo: DataRowMetadataOntology):
@@ -267,4 +275,4 @@ def test_parse_raw_metadata(mdo):
267275

268276
for row in parsed:
269277
for field in row.fields:
270-
assert mdo._parse_upsert(field)
278+
assert mdo._parse_upsert(field)

0 commit comments

Comments
 (0)