From 99f8d5daeab2abcad7d1a3401f4747ecd5e37653 Mon Sep 17 00:00:00 2001 From: antheas Date: Tue, 12 Sep 2023 11:35:32 +0000 Subject: [PATCH] fix categorical dtype warning --- src/pasteur/extras/transformers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pasteur/extras/transformers.py b/src/pasteur/extras/transformers.py index 2809dfe..e189fba 100644 --- a/src/pasteur/extras/transformers.py +++ b/src/pasteur/extras/transformers.py @@ -2,7 +2,7 @@ import numpy as np import pandas as pd -from pandas.api.types import is_categorical_dtype, is_float_dtype +from pandas.api.types import is_float_dtype from pasteur.attribute import Attributes from pasteur.transform import RefTransformer, Transformer @@ -147,7 +147,7 @@ def transform(self, data: pd.Series) -> pd.DataFrame: out_col = data.map(mapping) # Handle categorical columns without blowing them up to full blown columns - if is_categorical_dtype(out_col): + if isinstance(out_col, pd.CategoricalDtype): out_col = out_col.cat.add_categories(range(self.ofs)) # Handle NAs correctly @@ -166,7 +166,7 @@ def transform(self, data: pd.Series) -> pd.DataFrame: ), f"Uknown values found in '{self.col}', but no unknown value provided." # Remove old categories to change dtype - if is_categorical_dtype(out_col): + if isinstance(out_col, pd.CategoricalDtype): out_col = out_col.cat.set_categories(range(self.domain)) return pd.DataFrame(out_col.astype(type))