Skip to content

Commit 6854ac8

Browse files
Alexandra CotaAlexandra Cota
authored andcommitted
edit docstrings in client.py and project.py
1 parent c6995a9 commit 6854ac8

File tree

2 files changed

+49
-36
lines changed

2 files changed

+49
-36
lines changed

labelbox/client.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Client:
3232

3333
def __init__(self, api_key=None,
3434
endpoint='https://api.labelbox.com/graphql'):
35-
""" Create and initialize a Labelbox Client.
35+
""" Creates and initializes a Labelbox Client.
3636
3737
Args:
3838
api_key (str): API key. If None, the key is obtained from
@@ -63,19 +63,20 @@ def execute(self, query, params=None, timeout=10.0):
6363
in appropriate labelbox.exceptions.LabelboxError subtypes.
6464
6565
Args:
66-
query (str): the query to execute.
67-
params (dict): query parameters referenced within the query.
66+
query (str): The query to execute.
67+
params (dict): Query parameters referenced within the query.
6868
timeout (float): Max allowed time for query execution,
6969
in seconds.
70-
Return:
70+
Returns:
7171
dict, parsed JSON response.
7272
Raises:
7373
labelbox.exceptions.AuthenticationError: If authentication
7474
failed.
75-
labelbox.exceptions.InvalidQueryError: If `query` is not
75+
labelbox.exceptions.InvalidQueryError: If `query` was not
7676
syntactically or semantically valid (checked server-side).
7777
labelbox.exceptions.ApiLimitError: If the server API limit was
78-
exceeded. Check Labelbox documentation to see API limits.
78+
exceeded. See "How to import data" documentation to see
79+
API limits.
7980
labelbox.exceptions.TimeoutError: If response was not received
8081
in `timeout` seconds.
8182
labelbox.exceptions.NetworkError: If an unknown error occurred
@@ -172,12 +173,13 @@ def check_errors(keywords, *path):
172173

173174
def upload_data(self, data):
174175
""" Uploads the given data (bytes) to Labelbox.
176+
175177
Args:
176-
data (bytes): the data to upload.
177-
Return:
178+
data (bytes): The data to upload.
179+
Returns:
178180
str, the URL of uploaded data.
179181
Raises:
180-
labelbox.exceptions.LabelboxError: if upload failes.
182+
labelbox.exceptions.LabelboxError: If upload failed.
181183
"""
182184
request_data = {
183185
"operations": json.dumps({
@@ -213,7 +215,7 @@ def _get_single(self, db_object_type, uid):
213215
Args:
214216
db_object_type (type): DbObject subclass.
215217
uid (str): Unique ID of the row.
216-
Return:
218+
Returns:
217219
Object of `db_object_type`.
218220
Raises:
219221
labelbox.exceptions.ResourceNotFoundError: If there is no object
@@ -230,9 +232,10 @@ def _get_single(self, db_object_type, uid):
230232

231233
def get_project(self, project_id):
232234
""" Gets a single Project with the given ID.
235+
233236
Args:
234237
project_id (str): Unique ID of the Project.
235-
Return:
238+
Returns:
236239
The sought Project.
237240
Raises:
238241
labelbox.exceptions.ResourceNotFoundError: If there is no
@@ -242,9 +245,10 @@ def get_project(self, project_id):
242245

243246
def get_dataset(self, dataset_id):
244247
""" Gets a single Dataset with the given ID.
248+
245249
Args:
246250
dataset_id (str): Unique ID of the Dataset.
247-
Return:
251+
Returns:
248252
The sought Dataset.
249253
Raises:
250254
labelbox.exceptions.ResourceNotFoundError: If there is no
@@ -267,7 +271,7 @@ def _get_all(self, db_object_type, where):
267271
db_object_type (type): DbObject subclass.
268272
where (Comparison, LogicalOperation or None): The `where` clause
269273
for filtering.
270-
Return:
274+
Returns:
271275
An iterable of `db_object_type` instances.
272276
"""
273277
not_deleted = db_object_type.deleted == False
@@ -284,7 +288,7 @@ def get_projects(self, where=None):
284288
Args:
285289
where (Comparison, LogicalOperation or None): The `where` clause
286290
for filtering.
287-
Return:
291+
Returns:
288292
An iterable of Projects (typically a PaginatedCollection).
289293
"""
290294
return self._get_all(Project, where)
@@ -295,7 +299,7 @@ def get_datasets(self, where=None):
295299
Args:
296300
where (Comparison, LogicalOperation or None): The `where` clause
297301
for filtering.
298-
Return:
302+
Returns:
299303
An iterable of Datasets (typically a PaginatedCollection).
300304
"""
301305
return self._get_all(Dataset, where)
@@ -306,23 +310,23 @@ def get_labeling_frontends(self, where=None):
306310
Args:
307311
where (Comparison, LogicalOperation or None): The `where` clause
308312
for filtering.
309-
Return:
313+
Returns:
310314
An iterable of LabelingFrontends (typically a PaginatedCollection).
311315
"""
312316
return self._get_all(LabelingFrontend, where)
313317

314318
def _create(self, db_object_type, data):
315-
""" Creates a object on the server. Attribute values are
319+
""" Creates an object on the server. Attribute values are
316320
passed as keyword arguments:
317321
318322
Args:
319323
db_object_type (type): A DbObjectType subtype.
320324
data (dict): Keys are attributes or their names (in Python,
321325
snake-case convention) and values are desired attribute values.
322-
Return:
323-
a new object of the given DB object type.
326+
Returns:
327+
A new object of the given DB object type.
324328
Raises:
325-
InvalidAttributeError: in case the DB object type does not contain
329+
InvalidAttributeError: If the DB object type does not contain
326330
any of the attribute names given in `data`.
327331
"""
328332
# Convert string attribute names to Field or Relationship objects.
@@ -347,10 +351,10 @@ def create_dataset(self, **kwargs):
347351
Keyword arguments with new Dataset attribute values.
348352
Keys are attribute names (in Python, snake-case convention) and
349353
values are desired attribute values.
350-
Return:
351-
a new Dataset object.
354+
Returns:
355+
A new Dataset object.
352356
Raises:
353-
InvalidAttributeError: in case the Dataset type does not contain
357+
InvalidAttributeError: If the Dataset type does not contain
354358
any of the attribute names given in kwargs.
355359
"""
356360
return self._create(Dataset, kwargs)
@@ -364,10 +368,10 @@ def create_project(self, **kwargs):
364368
Keyword arguments with new Project attribute values.
365369
Keys are attribute names (in Python, snake-case convention) and
366370
values are desired attribute values.
367-
Return:
368-
a new Project object.
371+
Returns:
372+
A new Project object.
369373
Raises:
370-
InvalidAttributeError: in case the Project type does not contain
374+
InvalidAttributeError: If the Project type does not contain
371375
any of the attribute names given in kwargs.
372376
"""
373377
return self._create(Project, kwargs)

labelbox/schema/project.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Project(DbObject, Updateable, Deletable):
4343

4444
def create_label(self, **kwargs):
4545
""" Creates a label on this Project.
46+
4647
Kwargs:
4748
Label attributes. At the minimum the label `DataRow`.
4849
"""
@@ -107,9 +108,10 @@ def labels(self, datasets=None, order_by=None):
107108
def export_labels(self, timeout_seconds=60):
108109
""" Calls the server-side Label exporting that generates a JSON
109110
payload, and returns the URL to that payload.
111+
110112
Args:
111113
timeout_seconds (float): Max waiting time, in seconds.
112-
Return:
114+
Returns:
113115
URL of the data file with this Project's labels. If the server
114116
didn't generate during the `timeout_seconds` period, None
115117
is returned.
@@ -136,6 +138,7 @@ def export_labels(self, timeout_seconds=60):
136138

137139
def labeler_performance(self):
138140
""" Returns the labeler performances for this Project.
141+
139142
Returns:
140143
A PaginatedCollection of LabelerPerformance objects.
141144
"""
@@ -161,9 +164,10 @@ def create_labeler_performance(client, result):
161164

162165
def review_metrics(self, net_score):
163166
""" Returns this Project's review metrics.
167+
164168
Args:
165169
net_score (None or Review.NetScore): Indicates desired metric.
166-
Return:
170+
Returns:
167171
int, aggregation count of reviews for given net_score.
168172
"""
169173
if net_score not in (None,) + tuple(Entity.Review.NetScore):
@@ -180,8 +184,10 @@ def review_metrics(self, net_score):
180184

181185
def setup(self, labeling_frontend, labeling_frontend_options):
182186
""" Finalizes the Project setup.
187+
183188
Args:
184-
labeling_frontend (LabelingFrontend): The labeling frontend to use.
189+
labeling_frontend (LabelingFrontend): Which UI to use to label the
190+
data.
185191
labeling_frontend_options (dict or str): Labeling frontend options,
186192
a.k.a. project ontology. If given a `dict` it will be converted
187193
to `str` using `json.dumps`.
@@ -210,8 +216,8 @@ def set_labeling_parameter_overrides(self, data):
210216
Args:
211217
data (iterable): An iterable of tuples. Each tuple must contain
212218
(DataRow, priority, numberOfLabels) for the new override.
213-
Return:
214-
bool indicating if the operation was a success.
219+
Returns:
220+
bool, indicates if the operation was a success.
215221
"""
216222
data_str = ",\n".join(
217223
"{dataRow: {id: \"%s\"}, priority: %d, numLabels: %d }" % (
@@ -226,10 +232,11 @@ def set_labeling_parameter_overrides(self, data):
226232

227233
def unset_labeling_parameter_overrides(self, data_rows):
228234
""" Removes labeling parameter overrides to this project.
235+
229236
Args:
230237
data_rows (iterable): An iterable of DataRows.
231-
Return:
232-
bool indicating if the operation was a success.
238+
Returns:
239+
bool, indicates if the operation was a success.
233240
"""
234241
id_param = "projectId"
235242
query_str = """mutation UnsetLabelingParameterOverridesPyApi($%s: ID!){
@@ -241,7 +248,8 @@ def unset_labeling_parameter_overrides(self, data_rows):
241248
return res["project"]["unsetLabelingParameterOverrides"]["success"]
242249

243250
def upsert_review_queue(self, quota_factor):
244-
""" Reinitiate the review queue for this project.
251+
""" Reinitiates the review queue for this project.
252+
245253
Args:
246254
quota_factor (float): Which part (percentage) of the queue
247255
to reinitiate. Between 0 and 1.
@@ -257,11 +265,12 @@ def upsert_review_queue(self, quota_factor):
257265

258266

259267
def extend_reservations(self, queue_type):
260-
""" Extend all the current reservations for the current user on the given
268+
""" Extends all the current reservations for the current user on the given
261269
queue type.
270+
262271
Args:
263272
queue_type (str): Either "LabelingQueue" or "ReviewQueue"
264-
Return:
273+
Returns:
265274
int, the number of reservations that were extended.
266275
"""
267276
if queue_type not in ("LabelingQueue", "ReviewQueue"):

0 commit comments

Comments
 (0)