|
41 | 41 | # pandas. |
42 | 42 | have_pandas_categorical = (have_pandas and hasattr(pandas, "Categorical")) |
43 | 43 | if not have_pandas: |
44 | | - have_pandas_categorical_dtype = False |
45 | 44 | _pandas_is_categorical_dtype = None |
46 | 45 | else: |
47 | | - if hasattr(pandas, "api"): |
48 | | - # This is available starting in pandas v0.19.0 |
49 | | - have_pandas_categorical_dtype = True |
| 46 | + if hasattr(pandas, "CategoricalDtype"): # pandas >= 0.25 |
| 47 | + _pandas_is_categorical_dtype = lambda x: isinstance(getattr(x, "dtype", x), pandas.CategoricalDtype) |
| 48 | + elif hasattr(pandas, "api"): # pandas >= 0.19 |
50 | 49 | _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) |
60 | | - else: |
61 | | - # This is needed for pandas v0.18.0 and earlier |
| 50 | + else: # pandas <=0.18 |
62 | 51 | _pandas_is_categorical_dtype = getattr(pandas.core.common, |
63 | 52 | "is_categorical_dtype", None) |
64 | | - have_pandas_categorical_dtype = (_pandas_is_categorical_dtype |
65 | | - is not None) |
| 53 | +have_pandas_categorical_dtype = _pandas_is_categorical_dtype is not None |
66 | 54 |
|
67 | 55 |
|
68 | 56 | # Passes through Series and DataFrames, call np.asarray() on everything else |
|
0 commit comments