Skip to content

Commit 45938aa

Browse files
author
Thinh Nguyen
committed
.populate() call now returns a dict with success_count and error_list
1 parent ff6b81c commit 45938aa

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

datajoint/autopopulate.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ def populate(
160160
max_calls=None,
161161
display_progress=False,
162162
processes=1,
163-
return_success_count=False,
164163
make_kwargs=None,
165164
):
166165
"""
@@ -177,12 +176,13 @@ def populate(
177176
:param max_calls: if not None, populate at most this many keys
178177
:param display_progress: if True, report progress_bar
179178
:param processes: number of processes to use. Set to None to use all cores
180-
:param return_success_count: if True, return the count of successful `make()` calls.
181-
If suppress_errors is also True, returns a tuple: (success_count, errors)
182179
:param make_kwargs: Keyword arguments which do not affect the result of computation
183180
to be passed down to each ``make()`` call. Computation arguments should be
184181
specified within the pipeline e.g. using a `dj.Lookup` table.
185182
:type make_kwargs: dict, optional
183+
:return: a dict with two keys
184+
"success_count": the count of successful ``make()`` calls in this ``populate()`` call
185+
"error_list": the error list if "suppress_errors" is set to True, otherwise None
186186
"""
187187
if self.connection.in_transaction:
188188
raise DataJointError("Populate cannot be called during a transaction.")
@@ -275,12 +275,10 @@ def handler(signum, frame):
275275
if reserve_jobs:
276276
signal.signal(signal.SIGTERM, old_handler)
277277

278-
if suppress_errors and return_success_count:
279-
return sum(success_list), error_list
280-
if suppress_errors:
281-
return error_list
282-
if return_success_count:
283-
return sum(success_list)
278+
return {
279+
"success_count": sum(success_list),
280+
"error_list": error_list if suppress_errors else None,
281+
}
284282

285283
def _populate1(
286284
self, key, jobs, suppress_errors, return_exception_objects, make_kwargs=None
@@ -291,7 +289,8 @@ def _populate1(
291289
:param key: dict specifying job to populate
292290
:param suppress_errors: bool if errors should be suppressed and returned
293291
:param return_exception_objects: if True, errors must be returned as objects
294-
:return: (key, error) when suppress_errors=True, otherwise None
292+
:return: (key, error) when suppress_errors=True,
293+
True if successfully invoke one `make()` call, otherwise None
295294
"""
296295
make = self._make_tuples if hasattr(self, "_make_tuples") else self.make
297296

tests_old/test_autopopulate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ def test_populate_with_success_count(self):
5757
# test simple populate
5858
assert_true(self.subject, "root tables are empty")
5959
assert_false(self.experiment, "table already filled?")
60-
success_count = self.experiment.populate(return_success_count=True)
60+
ret = self.experiment.populate()
61+
success_count = ret["success_count"]
6162
assert_equal(len(self.experiment.key_source & self.experiment), success_count)
6263

6364
# test restricted populate
6465
assert_false(self.trial, "table already filled?")
6566
restriction = self.subject.proj(animal="subject_id").fetch("KEY")[0]
6667
d = self.trial.connection.dependencies
6768
d.load()
68-
success_count, _ = self.trial.populate(
69-
restriction, return_success_count=True, suppress_errors=True
70-
)
69+
ret = self.trial.populate(restriction, suppress_errors=True)
70+
success_count = ret["success_count"]
7171
assert_equal(len(self.trial.key_source & self.trial), success_count)
7272

7373
def test_populate_exclude_error_and_ignore_jobs(self):

0 commit comments

Comments
 (0)