12
12
def view_constraint_properties (row : pd .DataFrame ):
13
13
"""
14
14
Opens a GUI window to Modify a single constraint
15
- :param: row: a single row pandas DataFrame
16
- :returns : a modified constraints dict and table update
15
+ :param row: a single row pandas DataFrame
16
+ :return : a modified constraints dict and table update
17
17
"""
18
18
row_vals = row .to_dict (orient = "records" )[0 ]
19
19
for key , _ in row_vals .items ():
@@ -24,8 +24,8 @@ def view_constraint_properties(row: pd.DataFrame):
24
24
def update_constraint_properties (row : pd .DataFrame ):
25
25
"""
26
26
Opens a GUI window to Modify a single constraint
27
- :param: row: a single row pandas DataFrame
28
- :returns : a modified constraints dict and table update
27
+ :param row: a single row pandas DataFrame
28
+ :return : a modified constraints dict and table update
29
29
"""
30
30
new_vals = row .to_dict (orient = "records" )[0 ]
31
31
for key , _ in new_vals .items ():
@@ -36,8 +36,8 @@ def update_constraint_properties(row: pd.DataFrame):
36
36
def view_validation_data (data : pd .DataFrame ):
37
37
"""
38
38
Opens a GUI window to view the validation break records
39
- :param: row: a Verifier.validation_data DataFrame
40
- :returns : a GUI window with table display of breaks
39
+ :param row: a Verifier.validation_data DataFrame
40
+ :return : a GUI window with table display of breaks
41
41
"""
42
42
standard_validation_layout = [
43
43
[
@@ -83,9 +83,9 @@ def view_validation_data(data: pd.DataFrame):
83
83
def update_table (headings : list , data : pd .DataFrame ) -> pd .DataFrame :
84
84
"""
85
85
Update GUI validation tables
86
- :param: headings: a list of column names
87
- :param: data: a constraints dict
88
- :returns : an updated pandas DataFrame
86
+ :param headings: a list of column names
87
+ :param data: a constraints dict
88
+ :return : an updated pandas DataFrame
89
89
"""
90
90
cols = pd .DataFrame (columns = headings )
91
91
t_data = pd .DataFrame (data ).T .reset_index ()
@@ -98,7 +98,7 @@ def update_table(headings: list, data: pd.DataFrame) -> pd.DataFrame:
98
98
def get_constraints_dtypes (constraints : dict ) -> dict :
99
99
"""
100
100
Get new constraints data types
101
- :param: Constraints object
101
+ :param Constraints object
102
102
:return: dictionary of new data types
103
103
"""
104
104
new_dtypes = {
@@ -112,9 +112,10 @@ def get_constraints_dtypes(constraints: dict) -> dict:
112
112
113
113
class VerifierProgress (StandardVerifier ):
114
114
"""
115
- Overrides StandardVerifier validation function to
115
+ Overrides StandardVerifier validation function to
116
116
incorporate GUI progress bar functionality
117
117
"""
118
+
118
119
data : pd .DataFrame
119
120
constraints : dict
120
121
enforce_dtypes : bool = True
@@ -166,18 +167,20 @@ def main():
166
167
const = StandardConstraints ()
167
168
const .generate_constraints (frame )
168
169
c_update = update_table (STANDARD_HEADINGS , const .constraints )
169
- window ["-C_TABLE -" ].Update (c_update .values .tolist ())
170
-
171
- if event == "-C_TABLE -" :
172
- t_data_index = values ["-C_TABLE -" ]
170
+ window ["-STANDARD_TABLE -" ].Update (c_update .values .tolist ())
171
+
172
+ if event == "-STANDARD_TABLE -" :
173
+ t_data_index = values ["-STANDARD_TABLE -" ]
173
174
if len (t_data_index ) > 0 :
174
175
row_data = c_update .filter (items = t_data_index , axis = 0 )
175
176
view_constraint_properties (row_data )
176
-
177
+
177
178
if event == "Update" :
178
179
new_values = update_constraint_properties (row_data )
179
180
mod = {
180
- k : v for k , v in new_values .items () if v not in ["nan" , "NaN" ]
181
+ k : v
182
+ for k , v in new_values .items ()
183
+ if v not in ["nan" , "NaN" ]
181
184
}
182
185
dtype_mapping = {
183
186
"attribute" : str ,
@@ -187,7 +190,10 @@ def main():
187
190
"min_length" : lambda i : int (float (i )),
188
191
"max_length" : lambda i : int (float (i )),
189
192
"value_range" : lambda i : set (
190
- map (str .strip , i .strip ("}{" ).replace ("'" , "" ).split ("," ))
193
+ map (
194
+ str .strip ,
195
+ i .strip ("}{" ).replace ("'" , "" ).split ("," ),
196
+ )
191
197
),
192
198
"min_value" : float ,
193
199
"max_value" : float ,
@@ -201,14 +207,14 @@ def main():
201
207
del mod ["attribute" ]
202
208
const .modify_constraint (new_values ["attribute" ], mod )
203
209
m_update = update_table (STANDARD_HEADINGS , const .constraints )
204
- window ["-C_TABLE -" ].Update (m_update .values .tolist ())
205
-
210
+ window ["-STANDARD_TABLE -" ].Update (m_update .values .tolist ())
211
+
206
212
if event == "Recast dtypes" :
207
213
dtypes = get_constraints_dtypes (const .constraints )
208
214
frame = read_file (values ["-IN-" ], downcast = True , dtypes = dtypes )
209
215
const .generate_constraints (frame )
210
216
c_update = update_table (STANDARD_HEADINGS , const .constraints )
211
- window ["-C_TABLE -" ].Update (c_update .values .tolist ())
217
+ window ["-STANDARD_TABLE -" ].Update (c_update .values .tolist ())
212
218
if event == "-DTYPES-" :
213
219
ENFORCE_DTYPES = not ENFORCE_DTYPES
214
220
window ["-DTYPES-" ].update (
@@ -233,7 +239,7 @@ def main():
233
239
sg .Popup (f"Constraint for { v } but { v } not in data" )
234
240
else :
235
241
sg .PopupError ("No Data is loaded" )
236
-
242
+
237
243
if event == "-V_TABLE-" :
238
244
t_data_index = values ["-V_TABLE-" ]
239
245
row_data = v_update .filter (items = t_data_index , axis = 0 )
@@ -245,7 +251,7 @@ def main():
245
251
)
246
252
]
247
253
view_validation_data (validation_data )
248
-
254
+
249
255
# Custom constraints
250
256
if event == "Create" :
251
257
if "custom_constraints" not in locals ():
@@ -257,9 +263,13 @@ def main():
257
263
custom_constraints .add_custom_constraint (
258
264
values ["-NAME-" ], values ["-QUERY-" ]
259
265
)
260
- all_custom_constraints = custom_constraints .view_custom_constraints ()
261
- window ["-CUSTOM_TABLE-" ].Update (all_custom_constraints .values .tolist ())
262
-
266
+ all_custom_constraints = (
267
+ custom_constraints .view_custom_constraints ()
268
+ )
269
+ window ["-CUSTOM_TABLE-" ].Update (
270
+ all_custom_constraints .values .tolist ()
271
+ )
272
+
263
273
if event == "-CUSTOM_TABLE-" :
264
274
t_data_index = values ["-CUSTOM_TABLE-" ]
265
275
if len (t_data_index ) > 0 :
@@ -269,18 +279,22 @@ def main():
269
279
row_data = ct_update .filter (items = t_data_index , axis = 0 )
270
280
window ["-NAME-" ].Update (row_data ["name" ].values [0 ])
271
281
window ["-QUERY-" ].Update (row_data ["query" ].values [0 ])
272
-
282
+
273
283
if event == "Delete" :
274
284
custom_constraints .delete_custom_constraint (values ["-NAME-" ])
275
- all_custom_constraints = custom_constraints .view_custom_constraints ()
276
- window ["-CUSTOM_TABLE-" ].Update (all_custom_constraints .values .tolist ())
277
-
285
+ all_custom_constraints = (
286
+ custom_constraints .view_custom_constraints ()
287
+ )
288
+ window ["-CUSTOM_TABLE-" ].Update (
289
+ all_custom_constraints .values .tolist ()
290
+ )
291
+
278
292
if event == "Validate Custom" :
279
293
custom_verify = CustomVerifier (frame , custom_constraints )
280
294
window ["-CV_TABLE-" ].Update (
281
295
custom_verify .validation_summary .values .tolist ()
282
296
)
283
-
297
+
284
298
if event == "-CV_TABLE-" :
285
299
t_data_index = values ["-CV_TABLE-" ]
286
300
row_data = custom_verify .validation_summary .filter (
@@ -294,18 +308,18 @@ def main():
294
308
)
295
309
]
296
310
view_validation_data (validation_data )
297
-
311
+
298
312
# Loading and saving events
299
313
if event == "-SAVE_C_AS-" :
300
314
const .save_as (values ["-SAVE_C_AS-" ])
301
315
if event == "-READ_C-" :
302
316
const = StandardConstraints ()
303
317
const .read_constraints (values ["-READ_C-" ])
304
318
c_update = update_table (STANDARD_HEADINGS , const .constraints )
305
- window ["-C_TABLE -" ].Update (c_update .values .tolist ())
319
+ window ["-STANDARD_TABLE -" ].Update (c_update .values .tolist ())
306
320
if event == "-SAVE_V_AS-" :
307
321
valid .validation_summary .T .to_csv (values ["-SAVE_V_AS-" ])
308
-
322
+
309
323
if event == "-SAVE_CUSTOM_AS-" :
310
324
custom_constraints .save_as (values ["-SAVE_CUSTOM_AS-" ])
311
325
if event == "-READ_CUSTOM-" :
@@ -318,5 +332,6 @@ def main():
318
332
319
333
window .close ()
320
334
335
+
321
336
if __name__ == "__main__" :
322
337
main ()
0 commit comments