Skip to content

Commit

Permalink
Use isinstance(dtype, pd.CategoricalDtype) to check if a Pandas col…
Browse files Browse the repository at this point in the history
…umn is categorical because of deprecation in late versions
  • Loading branch information
druzsan committed Feb 13, 2024
1 parent 9ff5d8a commit bb7d770
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion renumics/spotlight/dataset/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def infer_dtype(column: pd.Series) -> dtypes.DType:

if pd.api.types.is_bool_dtype(column):
return dtypes.bool_dtype
if pd.api.types.is_categorical_dtype(column):
if isinstance(column.dtype, pd.CategoricalDtype):
return dtypes.CategoryDType(
{category: code for code, category in enumerate(column.cat.categories)}
)
Expand Down
4 changes: 2 additions & 2 deletions renumics/spotlight_plugins/core/pandas_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def get_column_values(
return values
if pd.api.types.is_datetime64_any_dtype(column):
return column.dt.tz_localize(None).to_numpy()
if pd.api.types.is_categorical_dtype(column):
if isinstance(column.dtype, pd.CategoricalDtype):
return column.cat.codes.to_numpy()
if pd.api.types.is_string_dtype(column):
column = column.astype(object).mask(column.isna(), None)
Expand Down Expand Up @@ -200,7 +200,7 @@ def _get_column_index(self, column_name: str) -> int:
def _determine_intermediate_dtype(column: pd.Series) -> dtypes.DType:
if pd.api.types.is_bool_dtype(column):
return dtypes.bool_dtype
if pd.api.types.is_categorical_dtype(column):
if isinstance(column.dtype, pd.CategoricalDtype):
return dtypes.CategoryDType(
{category: code for code, category in enumerate(column.cat.categories)}
)
Expand Down

0 comments on commit bb7d770

Please sign in to comment.