Skip to content

Commit

Permalink
Avoid false positives in _cast_to_numeric
Browse files Browse the repository at this point in the history
Previously, _cast_to_numeric would raise a TypeError if a column was
missing. We now check that a column exists before trying to cast it.

This does result in some redundant checking, as some functions call both
_require_columns and _cast_to_numeric. We may want to consider
refactoring to combine all of this functionality into a single DataFrame
validation step.

Signed-off-by: John Pennycook <[email protected]>
  • Loading branch information
Pennycook committed Sep 24, 2024
1 parent 02bd229 commit 8ed2454
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions p3analysis/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def _cast_to_numeric(df, columns):
"""
Check that the named columns are numeric, and cast them.
"""
_require_columns(df, columns)
result = df.copy(deep=True)
for column in columns:
try:
Expand Down

0 comments on commit 8ed2454

Please sign in to comment.