From 8ed24540e6c2569b32ea93dfea76d2fc23d6939c Mon Sep 17 00:00:00 2001 From: John Pennycook Date: Thu, 19 Sep 2024 10:12:13 +0100 Subject: [PATCH] Avoid false positives in _cast_to_numeric 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 --- p3analysis/_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/p3analysis/_utils.py b/p3analysis/_utils.py index a062a74..c656448 100644 --- a/p3analysis/_utils.py +++ b/p3analysis/_utils.py @@ -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: