Skip to content

CategoricalAccessor.categorical removed in 0.24.0rc1 #24751 #24754

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

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,7 @@ Deprecations
- :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`)
- :meth:`Series.nonzero` is deprecated and will be removed in a future version (:issue:`18262`)
- 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`)
- :attr:``CategoricalAccessor.categorical``, :attr:``CategoricalAccessor.name`` and :attr:``CategoricalAccessor.index`` have been deprecated and replaced by private :attr:``CategoricalAccessor._parent``, :attr:``CategoricalAccessor._name`` and :attr:``CategoricalAccessor._index``, respectively. (:issue:`24751`).

.. _whatsnew_0240.deprecations.datetimelike_int_ops:

Expand Down
24 changes: 22 additions & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2498,8 +2498,8 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
def __init__(self, data):
self._validate(data)
self._parent = data.values
self.index = data.index
self.name = data.name
self._index = data.index
self._name = data.name
self._freeze()

@staticmethod
Expand Down Expand Up @@ -2529,6 +2529,26 @@ def _delegate_method(self, name, *args, **kwargs):
if res is not None:
return Series(res, index=self.index, name=self.name)

@property
def categorical(self):
warn("s.cat.categorical has been deprecated",
DeprecationWarning,
stacklevel=2)
return self._parent

@property
def name(self):
warn("s.cat.name has been deprecated",
DeprecationWarning,
stacklevel=2)
return self._name

@property
def index(self):
warn("s.cat.index has been deprecated",
DeprecationWarning,
stacklevel=2)
return self._index

# utility routines

Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/arrays/categorical/test_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

import pandas as pd
import pandas.util.testing as tm


Expand All @@ -16,3 +17,15 @@ def test_tab_complete_warning(self, ip):
with tm.assert_produces_warning(None):
with provisionalcompleter('ignore'):
list(ip.Completer.completions('c.', 1))

def test_CategoricalAccessor_categorical_deprecation(object):
with tm.assert_produces_warning(DeprecationWarning):
pd.Series(['a', 'b'], dtype='category').cat.categorical.ordered

def test_CategoricalAccessor_name_deprecation(object):
with tm.assert_produces_warning(DeprecationWarning):
pd.Series(['a', 'b'], dtype='category').cat.name

def test_CategoricalAccessor_index_deprecation(object):
with tm.assert_produces_warning(DeprecationWarning):
pd.Series(['a', 'b'], dtype='category').cat.index