Skip to content

Commit

Permalink
Implementation for CategoricalAccessor.categorical removed in 0.24.0rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminr committed Jan 13, 2019
1 parent 6c84005 commit 5aa07d7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
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`)
- 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`).

.. _whatsnew_0240.deprecations.datetimelike_int_ops:

Expand Down
22 changes: 20 additions & 2 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2498,8 +2498,6 @@ 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._freeze()

@staticmethod
Expand Down Expand Up @@ -2529,6 +2527,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._parent

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

# 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

0 comments on commit 5aa07d7

Please sign in to comment.