Skip to content

Commit 58938e7

Browse files
committed
CLN: removed setter method of categorical's ordered attribute
1 parent d7c028d commit 58938e7

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

doc/source/whatsnew/v0.19.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ Removal of prior version deprecations/changes
506506

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

511512

pandas/core/categorical.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,6 @@ def _get_categories(self):
571571

572572
_ordered = None
573573

574-
def _set_ordered(self, value):
575-
""" Sets the ordered attribute to the boolean value """
576-
warn("Setting 'ordered' directly is deprecated, use 'set_ordered'",
577-
FutureWarning, stacklevel=2)
578-
self.set_ordered(value, inplace=True)
579-
580574
def set_ordered(self, value, inplace=False):
581575
"""
582576
Sets the ordered attribute to the boolean value
@@ -624,7 +618,7 @@ def _get_ordered(self):
624618
""" Gets the ordered attribute """
625619
return self._ordered
626620

627-
ordered = property(fget=_get_ordered, fset=_set_ordered)
621+
ordered = property(fget=_get_ordered)
628622

629623
def set_categories(self, new_categories, ordered=None, rename=False,
630624
inplace=False):

pandas/tests/test_categorical.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -808,13 +808,12 @@ def test_set_ordered(self):
808808
cat2.set_ordered(False, inplace=True)
809809
self.assertFalse(cat2.ordered)
810810

811-
# deperecated in v0.16.0
812-
with tm.assert_produces_warning(FutureWarning):
813-
cat.ordered = False
814-
self.assertFalse(cat.ordered)
815-
with tm.assert_produces_warning(FutureWarning):
811+
# removed in 0.19.0
812+
msg = "can\'t set attribute"
813+
with tm.assertRaisesRegexp(AttributeError, msg):
816814
cat.ordered = True
817-
self.assertTrue(cat.ordered)
815+
with tm.assertRaisesRegexp(AttributeError, msg):
816+
cat.ordered = False
818817

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

0 commit comments

Comments
 (0)