Skip to content

Commit 267b788

Browse files
NathanielVolfangojenkins
authored andcommitted
QPR-11900 -- Fix regression test comparison tool for handling optional_keys
1 parent a2daed4 commit 267b788

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

Tools/PythonTools/compare_files.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def compare_files_df(name, file_1, file_2, config):
304304
return False
305305

306306
# We check for columns that would be used as keys but are not always necessary,
307-
# e.g. netting set details, collect_regulations, post_regualtions
307+
# e.g. netting set details, collect_regulations, post_regulations
308308
if 'optional_keys' in config:
309309
optional_keys = config['optional_keys']
310310

@@ -320,10 +320,19 @@ def compare_files_df(name, file_1, file_2, config):
320320
logger.warning('The keys, %s, contain duplicates, %s.', str(combined_keys), str(dup_keys))
321321
return False
322322

323-
# For each optional key, check whether it is found in at each DataFrame. If so, add it to the keys.
323+
# For each optional key, check whether it is found in each DataFrame. If so, add it to the keys.
324+
missing_okeys = []
324325
for okey in optional_keys:
325326
if okey in df_1.columns and okey in df_2.columns:
326327
keys.append(okey)
328+
elif (okey in df_1.columns and not okey in df_2.columns) or (okey not in df_1.columns and okey in df_2.columns):
329+
missing_okeys.append(okey)
330+
331+
# Check that each optional key either exists in both DataFrames, or is missing in both. Otherwise, we fail the test.
332+
if missing_okeys:
333+
logger.warning('The keys, %s, are in one Dataframe but not the other.', str(missing_okeys))
334+
return False
335+
327336

328337
# If we are told to use only certain columns, drop the others in each DataFrame. We first check that both
329338
# DataFrames have all of the explicitly listed columns to use.

0 commit comments

Comments
 (0)