Skip to content

Commit a889cde

Browse files
authored
remove pandas deprecation warning (pydata#199)
1 parent 34f6384 commit a889cde

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

patsy/util.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@
4747
if hasattr(pandas, "api"):
4848
# This is available starting in pandas v0.19.0
4949
have_pandas_categorical_dtype = True
50-
_pandas_is_categorical_dtype = pandas.api.types.is_categorical_dtype
50+
_pandas_is_categorical_dtype = getattr(pandas.api.types, "is_categorical_dtype", None)
51+
# pandas.api.types._pandas_is_categorical_dtype is deprecated in pandas v2.1.0
52+
if _pandas_is_categorical_dtype is not None:
53+
import warnings
54+
with warnings.catch_warnings(record=True) as w:
55+
_pandas_is_categorical_dtype(int)
56+
if len(w) > 0 and issubclass(w[-1].category, FutureWarning):
57+
_pandas_is_categorical_dtype = None
58+
else:
59+
_pandas_is_categorical_dtype = lambda x: isinstance(x, pandas.CategoricalDType)
5160
else:
5261
# This is needed for pandas v0.18.0 and earlier
5362
_pandas_is_categorical_dtype = getattr(pandas.core.common,

0 commit comments

Comments
 (0)