Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions datacompy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1088,14 +1088,21 @@ def get_merged_columns(
What suffix was used to distinguish when the original dataframe was
overlapping with the other merged dataframe.
"""
# Precompute column sets for O(1) lookups (core optimization)
merged_cols = merged_df.columns
merged_cols_set = set(merged_cols)
columns = []
suffix_str = "_" + suffix
for col in original_df.columns:
if col in merged_df.columns:
if col in merged_cols_set:
columns.append(col)
elif col + "_" + suffix in merged_df.columns:
columns.append(col + "_" + suffix)
else:
raise ValueError("Column not found: %s", col)
col_suffixed = col + suffix_str
if col_suffixed in merged_cols_set:
columns.append(col_suffixed)
else:
# Preserve the behavior & exception type/message
raise ValueError("Column not found: %s", col)
return columns


Expand Down