@@ -63,7 +63,8 @@ def _rename_attributes(table, props):
63
63
if props ['aliased' ] else table .proj ())
64
64
65
65
if self ._key_source is None :
66
- parents = self .target .parents (primary = True , as_objects = True , foreign_key_info = True )
66
+ parents = self .target .parents (
67
+ primary = True , as_objects = True , foreign_key_info = True )
67
68
if not parents :
68
69
raise DataJointError ('A table must have dependencies '
69
70
'from its primary key for auto-populate to work' )
@@ -74,17 +75,19 @@ def _rename_attributes(table, props):
74
75
75
76
def make (self , key ):
76
77
"""
77
- Derived classes must implement method `make` that fetches data from tables that are
78
- above them in the dependency hierarchy, restricting by the given key, computes dependent
79
- attributes, and inserts the new tuples into self.
78
+ Derived classes must implement method `make` that fetches data from tables
79
+ above them in the dependency hierarchy, restricting by the given key,
80
+ computes secondary attributes, and inserts the new tuples into self.
80
81
"""
81
- raise NotImplementedError ('Subclasses of AutoPopulate must implement the method `make`' )
82
+ raise NotImplementedError (
83
+ 'Subclasses of AutoPopulate must implement the method `make`' )
82
84
83
85
@property
84
86
def target (self ):
85
87
"""
86
88
:return: table to be populated.
87
- In the typical case, dj.AutoPopulate is mixed into a dj.Table class by inheritance and the target is self.
89
+ In the typical case, dj.AutoPopulate is mixed into a dj.Table class by
90
+ inheritance and the target is self.
88
91
"""
89
92
return self
90
93
@@ -111,11 +114,14 @@ def _jobs_to_do(self, restrictions):
111
114
112
115
if not isinstance (todo , QueryExpression ):
113
116
raise DataJointError ('Invalid key_source value' )
114
- # check if target lacks any attributes from the primary key of key_source
117
+
115
118
try :
119
+ # check if target lacks any attributes from the primary key of key_source
116
120
raise DataJointError (
117
- 'The populate target lacks attribute %s from the primary key of key_source' % next (
118
- name for name in todo .heading .primary_key if name not in self .target .heading ))
121
+ 'The populate target lacks attribute %s '
122
+ 'from the primary key of key_source' % next (
123
+ name for name in todo .heading .primary_key
124
+ if name not in self .target .heading ))
119
125
except StopIteration :
120
126
pass
121
127
return (todo & AndList (restrictions )).proj ()
@@ -126,7 +132,8 @@ def populate(self, *restrictions, suppress_errors=False, return_exception_object
126
132
"""
127
133
table.populate() calls table.make(key) for every primary key in self.key_source
128
134
for which there is not already a tuple in table.
129
- :param restrictions: a list of restrictions each restrict (table.key_source - target.proj())
135
+ :param restrictions: a list of restrictions each restrict
136
+ (table.key_source - target.proj())
130
137
:param suppress_errors: if True, do not terminate execution.
131
138
:param return_exception_objects: return error objects instead of just error messages
132
139
:param reserve_jobs: if True, reserve jobs to populate in asynchronous fashion
@@ -259,5 +266,6 @@ def progress(self, *restrictions, display=True):
259
266
print ('%-20s' % self .__class__ .__name__ ,
260
267
'Completed %d of %d (%2.1f%%) %s' % (
261
268
total - remaining , total , 100 - 100 * remaining / (total + 1e-12 ),
262
- datetime .datetime .strftime (datetime .datetime .now (), '%Y-%m-%d %H:%M:%S' )), flush = True )
269
+ datetime .datetime .strftime (datetime .datetime .now (),
270
+ '%Y-%m-%d %H:%M:%S' )), flush = True )
263
271
return remaining , total
0 commit comments