|
13 | 13 | from tqdm import tqdm |
14 | 14 |
|
15 | 15 | from .errors import DataJointError, LostConnectionError |
16 | | -from .expression import AndList, QueryExpression |
| 16 | +from .expression import AndList |
17 | 17 |
|
18 | 18 | # noinspection PyExceptionInherit,PyCallingNonCallable |
19 | 19 |
|
@@ -167,34 +167,6 @@ def jobs(self): |
167 | 167 | self._jobs_table = JobsTable(self) |
168 | 168 | return self._jobs_table |
169 | 169 |
|
170 | | - def _jobs_to_do(self, restrictions): |
171 | | - """ |
172 | | - :return: the query yielding the keys to be computed (derived from self.key_source) |
173 | | - """ |
174 | | - if self.restriction: |
175 | | - raise DataJointError( |
176 | | - "Cannot call populate on a restricted table. Instead, pass conditions to populate() as arguments." |
177 | | - ) |
178 | | - todo = self.key_source |
179 | | - |
180 | | - # key_source is a QueryExpression subclass -- trigger instantiation |
181 | | - if inspect.isclass(todo) and issubclass(todo, QueryExpression): |
182 | | - todo = todo() |
183 | | - |
184 | | - if not isinstance(todo, QueryExpression): |
185 | | - raise DataJointError("Invalid key_source value") |
186 | | - |
187 | | - try: |
188 | | - # check if target lacks any attributes from the primary key of key_source |
189 | | - raise DataJointError( |
190 | | - "The populate target lacks attribute %s " |
191 | | - "from the primary key of key_source" |
192 | | - % next(name for name in todo.heading.primary_key if name not in self.heading) |
193 | | - ) |
194 | | - except StopIteration: |
195 | | - pass |
196 | | - return (todo & AndList(restrictions)).proj() |
197 | | - |
198 | 170 | def populate( |
199 | 171 | self, |
200 | 172 | *restrictions, |
@@ -243,6 +215,11 @@ def populate( |
243 | 215 | if self.connection.in_transaction: |
244 | 216 | raise DataJointError("Populate cannot be called during a transaction.") |
245 | 217 |
|
| 218 | + if self.restriction: |
| 219 | + raise DataJointError( |
| 220 | + "Cannot call populate on a restricted table. " "Instead, pass conditions to populate() as arguments." |
| 221 | + ) |
| 222 | + |
246 | 223 | valid_order = ["original", "reverse", "random"] |
247 | 224 | if order not in valid_order: |
248 | 225 | raise DataJointError("The order argument must be one of %s" % str(valid_order)) |
@@ -272,7 +249,8 @@ def handler(signum, frame): |
272 | 249 | else: |
273 | 250 | # Legacy behavior: get keys from key_source |
274 | 251 | if keys is None: |
275 | | - keys = (self._jobs_to_do(restrictions) - self).fetch("KEY", limit=limit) |
| 252 | + todo = (self.key_source & AndList(restrictions)).proj() |
| 253 | + keys = (todo - self).fetch("KEY", limit=limit) |
276 | 254 |
|
277 | 255 | if order == "reverse": |
278 | 256 | keys.reverse() |
@@ -457,7 +435,7 @@ def progress(self, *restrictions, display=False): |
457 | 435 | Report the progress of populating the table. |
458 | 436 | :return: (remaining, total) -- numbers of tuples to be populated |
459 | 437 | """ |
460 | | - todo = self._jobs_to_do(restrictions) |
| 438 | + todo = (self.key_source & AndList(restrictions)).proj() |
461 | 439 | total = len(todo) |
462 | 440 | remaining = len(todo - self) |
463 | 441 | if display: |
|
0 commit comments