pydata / patsy

Describing statistical models in Python using symbolic formulas
Other
954 stars 104 forks source link

Deprecation Warning from pandas #198

Closed EpigeneMax closed 11 months ago

EpigeneMax commented 11 months ago

patsy uses functions from pandas that are deprecated:

patsy/util.py:672: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
  return _pandas_is_categorical_dtype(dt)

I'll take a look and try to make a PR for this.

lesteve commented 10 months ago

It does not look like this issue has gone completely gone away somehow. We see something similar with patsy 0.5.5 inside the scikit-learn CI where we turn warnings into errors for our gallery examples.

I have to say I don't fully follow the logic of #199, maybe I post more comments in the PR about my questions ... in our case it made it slightly worse since the warning is at patsy import time rather than only when you use patsy.util.is_pandas_categorical and it seems like we were only using basic seaborn functionality which did not need patsy.util.is_pandas_categorical.

To reproduce (pandas >= 2.1.0 which is the version that deprecated is_categorical_dtype see this):

PYTHONWARNINGS=error::DeprecationWarning \
    python -c 'import patsy.util; patsy.util.safe_is_pandas_categorical_dtype(int)'

With patsy 0.5.5 you get the error during patsy import, with patsy 0.5.4 you get the warning when calling the patsy.util.safe_is_pandas_categorical.

lesteve commented 10 months ago

To make things a bit more complicated, one thing I noticed is that pandas may raise a DeprecationWarning or a FutureWarning depending on the pandas version. Apparently it was a FutureWarning from 2.1.0 until 2.1.3 and is now a DeprecationWarning in 2.1.4.

Context: https://github.com/pandas-dev/pandas/issues/54970 and https://github.com/pandas-dev/pandas/pull/56377.

EpigeneMax commented 10 months ago

Thanks for reporting this, @lesteve.

The patch in #199 indeed moves the warning at import time, and only catches FutureWarning, not DeprecationWarning. With #203 I see no warning with pandas 2.1.4.

matthewwardrop commented 10 months ago

I noted that as well, but assumed your patch was about making things work when this functionality is eventually removed, and less about suppressing the warnings themselves.... but I can totally see why you'd want to remove those warnings.