Skip to content

Commit 96ec6c5

Browse files
committed
Fix column name parsing when regex=False in pandera DataFrame validators
1 parent bb95f1b commit 96ec6c5

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

echopop/utils/validate_df.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,12 @@ def validate_df(cls, data: pd.DataFrame, filename: Optional[str] = None) -> pd.D
195195
for col in df.columns:
196196
# ---- Regular expression matching
197197
if re.match(column_name, col):
198-
# ---- Retrieve the column name
199-
col_name = re.match(column_name, col).group(0)
200-
# ---- Collect, if valid
198+
# ---- Collect, if valid and `regex = True`
201199
if cls.to_schema().columns[column_name].regex:
202200
valid_cols.append(col)
203-
else:
204-
valid_cols.append(col_name)
201+
# ---- Collect if exact match
202+
elif col == column_name:
203+
valid_cols.append(column_name)
205204
# ---- Check if null values are allowed
206205
if not cls.to_schema().columns[column_name].nullable:
207206
# ---- Get the violating indices
@@ -211,7 +210,7 @@ def validate_df(cls, data: pd.DataFrame, filename: Optional[str] = None) -> pd.D
211210
df[col].isna() | df[col].isin([np.inf, -np.inf])
212211
].to_list()
213212
}
214-
)
213+
)
215214
# ---- Initialize the list
216215
invalid_lst = []
217216
# ---- Extend the values

0 commit comments

Comments
 (0)