Skip to content

Commit

Permalink
fix categorical dtype warning
Browse files Browse the repository at this point in the history
  • Loading branch information
antheas committed Sep 12, 2023
1 parent cdaac04 commit 99f8d5d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pasteur/extras/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit 99f8d5d

Please # to comment.