Skip to content

Commit 17aa444

Browse files
committed
Dataset, DatasetItem, and Client
1 parent 51955b5 commit 17aa444

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

nucleus/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
)
142142

143143

144+
144145
class NucleusClient:
145146
"""
146147
Nucleus client.
@@ -149,9 +150,21 @@ class NucleusClient:
149150
def __init__(self, api_key: str, use_notebook: bool = False):
150151
self.api_key = api_key
151152
self.tqdm_bar = tqdm.tqdm
153+
self._use_notebook = use_notebook
152154
if use_notebook:
153155
self.tqdm_bar = tqdm_notebook.tqdm
154156

157+
def __repr__(self):
158+
return f"NucleusClient(api_key='{self.api_key}', use_notebook={self._use_notebook})"
159+
160+
def __eq__(self, other):
161+
if self.api_key == other.api_key:
162+
if self._use_notebook == other._use_notebook:
163+
return True
164+
return False
165+
166+
167+
155168
def list_models(self) -> List[Model]:
156169
"""
157170
Lists available models in your repo.

nucleus/dataset.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ def __init__(self, dataset_id: str, client):
3232
self.id = dataset_id
3333
self._client = client
3434

35+
def __repr__(self):
36+
return f"Dataset(dataset_id='{self.id}', client={self._client})"
37+
38+
def __eq__(self, other):
39+
if self.id == other.id:
40+
if self._client == other._client:
41+
return True
42+
return False
43+
3544
@property
3645
def name(self) -> str:
3746
return self.info().get(DATASET_NAME_KEY, "")

tests/helpers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,7 @@ def assert_polygon_prediction_matches_dict(
185185
prediction_instance, prediction_dict
186186
)
187187
assert prediction_instance.confidence == prediction_dict["confidence"]
188+
189+
190+
def test_repr(test_object: any):
191+
assert eval(str(test_object)) == test_object

tests/test_annotation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
)
2222
from nucleus.constants import ERROR_PAYLOAD
2323

24-
24+
# Have to define here in order to have access to all relevant objects
2525
def test_repr(test_object: any):
2626
assert eval(str(test_object)) == test_object
2727

28-
2928
def test_reprs():
3029
[
3130
test_repr(SegmentationAnnotation.from_json(_))

tests/test_dataset.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
reference_id_from_url,
99
)
1010

11-
from nucleus import Dataset, DatasetItem, UploadResponse
11+
from nucleus import Dataset, DatasetItem, UploadResponse, NucleusClient
1212
from nucleus.constants import (
1313
NEW_ITEMS,
1414
UPDATED_ITEMS,
@@ -19,6 +19,28 @@
1919
)
2020

2121

22+
# Have to define here in order to have access to all relevant objects
23+
def test_repr(test_object: any):
24+
assert eval(str(test_object)) == test_object
25+
26+
def test_reprs():
27+
test_repr(DatasetItem(
28+
image_location="test_url",
29+
reference_id="test_reference_id",
30+
metadata={
31+
"made_with_pytest": True,
32+
"example_int": 0,
33+
"example_str": "hello",
34+
"example_float": 0.5,
35+
"example_dict": {
36+
"nested": True,
37+
},
38+
"example_list": ["hello", 1, False],
39+
},
40+
))
41+
test_repr(Dataset("test_dataset", NucleusClient(api_key="fake_key")))
42+
43+
2244
@pytest.fixture()
2345
def dataset(CLIENT):
2446
ds = CLIENT.create_dataset(TEST_DATASET_NAME)

0 commit comments

Comments
 (0)