Skip to content

Commit 5aa07d7

Browse files
committed
Implementation for CategoricalAccessor.categorical removed in 0.24.0rc1 pandas-dev#24751
1 parent 6c84005 commit 5aa07d7

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

doc/source/whatsnew/v0.24.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,7 @@ Deprecations
13091309
- :meth:`Series.clip_lower`, :meth:`Series.clip_upper`, :meth:`DataFrame.clip_lower` and :meth:`DataFrame.clip_upper` are deprecated and will be removed in a future version. Use ``Series.clip(lower=threshold)``, ``Series.clip(upper=threshold)`` and the equivalent ``DataFrame`` methods (:issue:`24203`)
13101310
- :meth:`Series.nonzero` is deprecated and will be removed in a future version (:issue:`18262`)
13111311
- Passing an integer to :meth:`Series.fillna` and :meth:`DataFrame.fillna` with ``timedelta64[ns]`` dtypes is deprecated, will raise ``TypeError`` in a future version. Use ``obj.fillna(pd.Timedelta(...))`` instead (:issue:`24694`)
1312+
- The ``name``, ``index`` and ``categorical`` attributes of ``CategoricalAccessor`` have been removed in 0.24.0rc1, but should be deprecated for the time being, raising an appropriate warning (:issue:`24751`).
13121313

13131314
.. _whatsnew_0240.deprecations.datetimelike_int_ops:
13141315

pandas/core/arrays/categorical.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -2498,8 +2498,6 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
24982498
def __init__(self, data):
24992499
self._validate(data)
25002500
self._parent = data.values
2501-
self.index = data.index
2502-
self.name = data.name
25032501
self._freeze()
25042502

25052503
@staticmethod
@@ -2529,6 +2527,26 @@ def _delegate_method(self, name, *args, **kwargs):
25292527
if res is not None:
25302528
return Series(res, index=self.index, name=self.name)
25312529

2530+
@property
2531+
def categorical(self):
2532+
warn("s.cat.categorical has been deprecated",
2533+
DeprecationWarning,
2534+
stacklevel=2)
2535+
return self._parent
2536+
2537+
@property
2538+
def name(self):
2539+
warn("s.cat.name has been deprecated",
2540+
DeprecationWarning,
2541+
stacklevel=2)
2542+
return self._parent
2543+
2544+
@property
2545+
def index(self):
2546+
warn("s.cat.index has been deprecated",
2547+
DeprecationWarning,
2548+
stacklevel=2)
2549+
return self._parent
25322550

25332551
# utility routines
25342552

pandas/tests/arrays/categorical/test_warnings.py

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
import pandas as pd
56
import pandas.util.testing as tm
67

78

@@ -16,3 +17,15 @@ def test_tab_complete_warning(self, ip):
1617
with tm.assert_produces_warning(None):
1718
with provisionalcompleter('ignore'):
1819
list(ip.Completer.completions('c.', 1))
20+
21+
def test_CategoricalAccessor_categorical_deprecation(object):
22+
with tm.assert_produces_warning(DeprecationWarning):
23+
pd.Series(['a', 'b'], dtype='category').cat.categorical.ordered
24+
25+
def test_CategoricalAccessor_name_deprecation(object):
26+
with tm.assert_produces_warning(DeprecationWarning):
27+
pd.Series(['a', 'b'], dtype='category').cat.name
28+
29+
def test_CategoricalAccessor_index_deprecation(object):
30+
with tm.assert_produces_warning(DeprecationWarning):
31+
pd.Series(['a', 'b'], dtype='category').cat.index

0 commit comments

Comments
 (0)