Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update is_categorical_dtype for pandas>=2.1.0 #105

Merged
merged 1 commit into from
Jan 22, 2024
Merged

Update is_categorical_dtype for pandas>=2.1.0 #105

merged 1 commit into from
Jan 22, 2024

Conversation

kddubey
Copy link
Contributor

@kddubey kddubey commented Jan 6, 2024

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.

Copy link

codecov bot commented Jan 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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
@@            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              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tomicapretto
Copy link
Collaborator

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
Copy link
Contributor Author

kddubey commented Jan 9, 2024

@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
Copy link
Collaborator

@kddubey thanks a lot for the contribution :)

@tomicapretto tomicapretto merged commit f6199f1 into bambinos:master Jan 22, 2024
6 checks passed
@kddubey kddubey deleted the update-is-categorical-dtype branch January 22, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants