bambinos / formulae

Formulas for mixed-effects models in Python
https://bambinos.github.io/formulae/
MIT License
56 stars 14 forks source link

Update is_categorical_dtype for pandas>=2.1.0 #105

Closed kddubey closed 9 months ago

kddubey commented 10 months ago

From https://pandas.pydata.org/docs/whatsnew/v2.1.0.html#other-deprecations:

Deprecated is_categorical_dtype(), use isinstance(obj.dtype, pd.CategoricalDtype) instead (GH 52527)

Currently, formulae will surface this warning for pandas>=2.1.0:

.../formulae/terms/call.py:108: FutureWarning: is_categorical_dtype is deprecated and will be removed in a future version. Use isinstance(dtype, CategoricalDtype) instead
  elif is_string_dtype(x) or is_categorical_dtype(x) or isinstance(x, CategoricalBox):

(As of pandas==2.1.4 this is a DeprecationWarning instead of a FutureWarning.)

The change in this PR should be backwards-compatible.

How has this been tested?

In a virtual env w/ pandas==1.3.4, I ran pytest. I also checked that this snippet of code is correct.

import pandas as pd
from formulae.utils import is_categorical_dtype

data = [1, 2, 3, 1, 2, 3]

data_cat = pd.Categorical(data)
assert is_categorical_dtype(data_cat)

data_num = pd.Series(data)
assert not is_categorical_dtype(data_num)

In a virtual env w/ pandas==2.1.4, I ran pytest. I also checked that the snippet of code above is still correct and doesn't raises a warning.

codecov[bot] commented 10 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (9f81578) 92.65% compared to head (e050737) 92.68%. Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #105 +/- ## ========================================== + Coverage 92.65% 92.68% +0.03% ========================================== Files 21 21 Lines 2219 2229 +10 ========================================== + Hits 2056 2066 +10 Misses 163 163 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

tomicapretto commented 9 months ago

Hi @kddubey! Thanks a lot for the PR. I'm writing to let you know that I see the contribution, but I still didn't have time to check the underlying issue very well. And I'm going to be travelling so I won't be able to check it for the next 2 weeks. Still, the code looks good and tests pass so that's great.

kddubey commented 9 months ago

@tomicapretto No worries. And thank you to you and the PyMC team for building bambi! It's a pleasure to explore and use. Happy travels :-)

tomicapretto commented 9 months ago

@kddubey thanks a lot for the contribution :)