Skip to content

CLN: removed setter method of categorical's ordered attribute #13671

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

Closed
Closed
Show file tree
Hide file tree
Changes from all 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.19.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ Removal of prior version deprecations/changes

- ``DataFrame.to_csv()`` has dropped the ``engine`` parameter, as was deprecated in 0.17.1 (:issue:`11274`, :issue:`13419`)
- ``DataFrame.to_dict()`` has dropped the ``outtype`` parameter in favor of ``orient`` (:issue:`13627`, :issue:`8486`)
- ``pd.Categorical`` has dropped setting of the ``ordered`` attribute directly in favor of the ``set_ordered`` method (:issue:`13671`)
- ``pd.Categorical`` has dropped the ``levels`` attribute in favour of ``categories`` (:issue:`8376`)


Expand Down
8 changes: 1 addition & 7 deletions pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,6 @@ def _get_categories(self):

_ordered = None

def _set_ordered(self, value):
""" Sets the ordered attribute to the boolean value """
warn("Setting 'ordered' directly is deprecated, use 'set_ordered'",
FutureWarning, stacklevel=2)
self.set_ordered(value, inplace=True)

def set_ordered(self, value, inplace=False):
"""
Sets the ordered attribute to the boolean value
Expand Down Expand Up @@ -624,7 +618,7 @@ def _get_ordered(self):
""" Gets the ordered attribute """
return self._ordered

ordered = property(fget=_get_ordered, fset=_set_ordered)
ordered = property(fget=_get_ordered)

def set_categories(self, new_categories, ordered=None, rename=False,
inplace=False):
Expand Down
11 changes: 5 additions & 6 deletions pandas/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,13 +808,12 @@ def test_set_ordered(self):
cat2.set_ordered(False, inplace=True)
self.assertFalse(cat2.ordered)

# deperecated in v0.16.0
with tm.assert_produces_warning(FutureWarning):
cat.ordered = False
self.assertFalse(cat.ordered)
with tm.assert_produces_warning(FutureWarning):
# removed in 0.19.0
msg = "can\'t set attribute"
with tm.assertRaisesRegexp(AttributeError, msg):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls change it to check AttributeError is raised.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

cat.ordered = True
self.assertTrue(cat.ordered)
with tm.assertRaisesRegexp(AttributeError, msg):
cat.ordered = False

def test_set_categories(self):
cat = Categorical(["a", "b", "c", "a"], ordered=True)
Expand Down