From a889cdea028c506ba7bdc7565d4dcf7512022abb Mon Sep 17 00:00:00 2001 From: Maximilien Colange <111890372+EpigeneMax@users.noreply.github.com> Date: Mon, 25 Dec 2023 05:53:08 +0100 Subject: [PATCH] remove pandas deprecation warning (#199) --- patsy/util.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/patsy/util.py b/patsy/util.py index fc7e815..71d0404 100644 --- a/patsy/util.py +++ b/patsy/util.py @@ -47,7 +47,16 @@ if hasattr(pandas, "api"): # This is available starting in pandas v0.19.0 have_pandas_categorical_dtype = True - _pandas_is_categorical_dtype = pandas.api.types.is_categorical_dtype + _pandas_is_categorical_dtype = getattr(pandas.api.types, "is_categorical_dtype", None) + # pandas.api.types._pandas_is_categorical_dtype is deprecated in pandas v2.1.0 + if _pandas_is_categorical_dtype is not None: + import warnings + with warnings.catch_warnings(record=True) as w: + _pandas_is_categorical_dtype(int) + if len(w) > 0 and issubclass(w[-1].category, FutureWarning): + _pandas_is_categorical_dtype = None + else: + _pandas_is_categorical_dtype = lambda x: isinstance(x, pandas.CategoricalDType) else: # This is needed for pandas v0.18.0 and earlier _pandas_is_categorical_dtype = getattr(pandas.core.common,