Skip to content

Commit 592ed7d

Browse files
author
Jihan Yin
committed
api working, tested
1 parent 58479c9 commit 592ed7d

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

nucleus/slice.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from .constants import DATASET_ITEM_ID_KEY
1+
from typing import List, Dict, Any
2+
from .constants import DATASET_ITEM_ID_KEY, REFERENCE_IDS_KEY
23

34

45
class Slice:
@@ -27,25 +28,37 @@ def info(self, id_type: str = DATASET_ITEM_ID_KEY) -> dict:
2728
"""
2829
return self._client.slice_info(self.slice_id, id_type)
2930

30-
def append(self, payload: dict) -> dict:
31+
def append(
32+
self,
33+
dataset_item_ids: List[str] = None,
34+
reference_ids: List[str] = None
35+
) -> dict:
3136
"""
3237
Appends to a slice from items already present in a dataset.
3338
The caller must exclusively use either datasetItemIds or reference_ids
3439
as a means of identifying items in the dataset.
3540
3641
:param
37-
payload:
38-
{
39-
"dataset_item_ids": List[str],
40-
"reference_ids": List[str],
41-
}
42-
42+
dataset_item_ids: List[str],
43+
reference_ids: List[str],
44+
4345
:return:
4446
{
4547
"slice_id": str,
4648
}
4749
"""
48-
response = self.client._make_request(
50+
if dataset_item_ids and reference_ids:
51+
raise Exception(
52+
"You cannot both dataset_item_ids and reference_ids"
53+
)
54+
55+
payload: Dict[str, Any] = {}
56+
if dataset_item_ids:
57+
payload[DATASET_ITEM_IDS_KEY] = dataset_item_ids
58+
if reference_ids:
59+
payload[REFERENCE_IDS_KEY] = reference_ids
60+
61+
response = self._client._make_request(
4962
payload, f"slice/{self.slice_id}/append"
5063
)
5164
return response

0 commit comments

Comments
 (0)