Skip to content

Commit 17fb35b

Browse files
authored
Merge pull request #110 from scaleapi/da-no-dataset-item-ids
No more null reference ids
2 parents fccb216 + d5a2a25 commit 17fb35b

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

nucleus/dataset_item.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from .annotation import is_local_path, Point3D
99
from .constants import (
10-
DATASET_ITEM_ID_KEY,
1110
IMAGE_URL_KEY,
1211
METADATA_KEY,
1312
ORIGINAL_IMAGE_URL_KEY,
@@ -91,11 +90,11 @@ class DatasetItemType(Enum):
9190
class DatasetItem: # pylint: disable=R0902
9291
image_location: Optional[str] = None
9392
reference_id: Optional[str] = None
94-
item_id: Optional[str] = None
9593
metadata: Optional[dict] = None
9694
pointcloud_location: Optional[str] = None
9795

9896
def __post_init__(self):
97+
assert self.reference_id is not None, "reference_id is required."
9998
assert bool(self.image_location) != bool(
10099
self.pointcloud_location
101100
), "Must specify exactly one of the image_location, pointcloud_location parameters"
@@ -127,14 +126,12 @@ def from_json(cls, payload: dict, is_scene=False):
127126
image_location=image_url,
128127
pointcloud_location=payload.get(POINTCLOUD_URL_KEY, None),
129128
reference_id=payload.get(REFERENCE_ID_KEY, None),
130-
item_id=payload.get(DATASET_ITEM_ID_KEY, None),
131129
metadata=payload.get(METADATA_KEY, {}),
132130
)
133131

134132
return cls(
135133
image_location=image_url,
136134
reference_id=payload.get(REFERENCE_ID_KEY, None),
137-
item_id=payload.get(DATASET_ITEM_ID_KEY, None),
138135
metadata=payload.get(METADATA_KEY, {}),
139136
)
140137

@@ -145,10 +142,8 @@ def to_payload(self, is_scene=False) -> dict:
145142
payload: Dict[str, Any] = {
146143
METADATA_KEY: self.metadata or {},
147144
}
148-
if self.reference_id:
149-
payload[REFERENCE_ID_KEY] = self.reference_id
150-
if self.item_id:
151-
payload[DATASET_ITEM_ID_KEY] = self.item_id
145+
146+
payload[REFERENCE_ID_KEY] = self.reference_id
152147

153148
if is_scene:
154149
if self.image_location:

tests/test_dataset.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ def check_is_expected_response(response):
177177
# Plain image upload
178178
ds_items_plain = []
179179
for url in TEST_IMG_URLS:
180-
ds_items_plain.append(DatasetItem(image_location=url))
180+
ds_items_plain.append(
181+
DatasetItem(
182+
image_location=url, reference_id=url.split("/")[-1] + "_plain"
183+
)
184+
)
181185
response = dataset.append(ds_items_plain)
182186
check_is_expected_response(response)
183187

@@ -189,15 +193,23 @@ def check_is_expected_response(response):
189193

190194
def test_dataset_append_local(CLIENT, dataset):
191195
ds_items_local_error = [
192-
DatasetItem(image_location=LOCAL_FILENAME, metadata={"test": math.nan})
196+
DatasetItem(
197+
image_location=LOCAL_FILENAME,
198+
metadata={"test": math.nan},
199+
reference_id="bad",
200+
)
193201
]
194202
with pytest.raises(ValueError) as e:
195203
dataset.append(ds_items_local_error)
196204
assert "Out of range float values are not JSON compliant" in str(
197205
e.value
198206
)
199207
ds_items_local = [
200-
DatasetItem(image_location=LOCAL_FILENAME, metadata={"test": 0})
208+
DatasetItem(
209+
image_location=LOCAL_FILENAME,
210+
metadata={"test": 0},
211+
reference_id=LOCAL_FILENAME.split("/")[-1],
212+
)
201213
]
202214

203215
response = dataset.append(ds_items_local)

0 commit comments

Comments
 (0)