Skip to content

Commit f3321cb

Browse files
committed
CLN: Removed levels attribute from Categorical
Closes gh-8376.
1 parent c9a27ed commit f3321cb

File tree

3 files changed

+3
-40
lines changed

3 files changed

+3
-40
lines changed

doc/source/whatsnew/v0.19.0.txt

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

468468
- ``DataFrame.to_csv()`` has dropped the ``engine`` parameter, as was deprecated in 0.17.1 (:issue:`11274`, :issue:`13419`)
469469
- ``DataFrame.to_dict()`` has dropped the ``outtype`` parameter in favor of ``orient`` (:issue:`13627`, :issue:`8486`)
470+
- ``pd.Categorical`` has dropped the ``levels`` attribute in favour of ``categories`` (:issue:`8376`)
470471

471472

472473
.. _whatsnew_0190.performance:

pandas/core/categorical.py

+2-28
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ class Categorical(PandasObject):
228228
__array_priority__ = 1000
229229
_typ = 'categorical'
230230

231-
def __init__(self, values, categories=None, ordered=False, name=None,
232-
fastpath=False, levels=None):
231+
def __init__(self, values, categories=None, ordered=False,
232+
name=None, fastpath=False):
233233

234234
if fastpath:
235235
# fast path
@@ -245,17 +245,6 @@ def __init__(self, values, categories=None, ordered=False, name=None,
245245
"name=\"something\")'")
246246
warn(msg, UserWarning, stacklevel=2)
247247

248-
# TODO: Remove after deprecation period in 2017/ after 0.18
249-
if levels is not None:
250-
warn("Creating a 'Categorical' with 'levels' is deprecated, use "
251-
"'categories' instead", FutureWarning, stacklevel=2)
252-
if categories is None:
253-
categories = levels
254-
else:
255-
raise ValueError("Cannot pass in both 'categories' and "
256-
"(deprecated) 'levels', use only "
257-
"'categories'", stacklevel=2)
258-
259248
# sanitize input
260249
if is_categorical_dtype(values):
261250

@@ -580,21 +569,6 @@ def _get_categories(self):
580569
categories = property(fget=_get_categories, fset=_set_categories,
581570
doc=_categories_doc)
582571

583-
def _set_levels(self, levels):
584-
""" set new levels (deprecated, use "categories") """
585-
warn("Assigning to 'levels' is deprecated, use 'categories'",
586-
FutureWarning, stacklevel=2)
587-
self.categories = levels
588-
589-
def _get_levels(self):
590-
""" Gets the levels (deprecated, use "categories") """
591-
warn("Accessing 'levels' is deprecated, use 'categories'",
592-
FutureWarning, stacklevel=2)
593-
return self.categories
594-
595-
# TODO: Remove after deprecation period in 2017/ after 0.18
596-
levels = property(fget=_get_levels, fset=_set_levels)
597-
598572
_ordered = None
599573

600574
def _set_ordered(self, value):

pandas/tests/test_categorical.py

-12
Original file line numberDiff line numberDiff line change
@@ -1559,18 +1559,6 @@ def test_deprecated_labels(self):
15591559
res = cat.labels
15601560
self.assert_numpy_array_equal(res, exp)
15611561

1562-
def test_deprecated_levels(self):
1563-
# TODO: levels is deprecated and should be removed in 0.18 or 2017,
1564-
# whatever is earlier
1565-
cat = pd.Categorical([1, 2, 3, np.nan], categories=[1, 2, 3])
1566-
exp = cat.categories
1567-
with tm.assert_produces_warning(FutureWarning):
1568-
res = cat.levels
1569-
self.assert_index_equal(res, exp)
1570-
with tm.assert_produces_warning(FutureWarning):
1571-
res = pd.Categorical([1, 2, 3, np.nan], levels=[1, 2, 3])
1572-
self.assert_index_equal(res.categories, exp)
1573-
15741562
def test_removed_names_produces_warning(self):
15751563

15761564
# 10482

0 commit comments

Comments
 (0)