Skip to content

Commit 7e1e7d8

Browse files
committed
API: Drop the name parameter from Categorical
Deprecated in 0.17.0 xref gh-10632
1 parent 026e748 commit 7e1e7d8

File tree

5 files changed

+9
-40
lines changed

5 files changed

+9
-40
lines changed

doc/source/whatsnew/v0.20.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ Removal of prior version deprecations/changes
734734
- The deprecated ``irow``, ``icol``, ``iget`` and ``iget_value`` methods are removed
735735
in favor of ``iloc`` and ``iat`` as explained :ref:`here <whatsnew_0170.deprecations>` (:issue:`10711`).
736736
- The deprecated ``DataFrame.iterkv()`` has been removed in favor of ``DataFrame.iteritems()`` (:issue:`10711`)
737-
737+
- The ``Categorical`` constructor has dropped the ``name`` parameter (:issue:`10632`)
738738

739739
.. _whatsnew_0200.performance:
740740

pandas/core/categorical.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ class Categorical(PandasObject):
231231
__array_priority__ = 1000
232232
_typ = 'categorical'
233233

234-
def __init__(self, values, categories=None, ordered=False,
235-
name=None, fastpath=False):
234+
def __init__(self, values, categories=None, ordered=False, fastpath=False):
236235

237236
self._validate_ordered(ordered)
238237

@@ -244,12 +243,6 @@ def __init__(self, values, categories=None, ordered=False,
244243
self._ordered = ordered
245244
return
246245

247-
if name is not None:
248-
msg = ("the 'name' keyword is removed, use 'name' with consumers "
249-
"of the categorical instead (e.g. 'Series(cat, "
250-
"name=\"something\")'")
251-
warn(msg, UserWarning, stacklevel=2)
252-
253246
# sanitize input
254247
if is_categorical_dtype(values):
255248

@@ -431,7 +424,7 @@ def from_array(cls, data, **kwargs):
431424
return cls(data, **kwargs)
432425

433426
@classmethod
434-
def from_codes(cls, codes, categories, ordered=False, name=None):
427+
def from_codes(cls, codes, categories, ordered=False):
435428
"""
436429
Make a Categorical type from codes and categories arrays.
437430
@@ -454,12 +447,6 @@ def from_codes(cls, codes, categories, ordered=False, name=None):
454447
categorical. If not given, the resulting categorical will be
455448
unordered.
456449
"""
457-
if name is not None:
458-
msg = ("the 'name' keyword is removed, use 'name' with consumers "
459-
"of the categorical instead (e.g. 'Series(cat, "
460-
"name=\"something\")'")
461-
warn(msg, UserWarning, stacklevel=2)
462-
463450
try:
464451
codes = np.asarray(codes, np.int64)
465452
except:

pandas/io/packers.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,7 @@ def decode(obj):
589589
from_codes = globals()[obj[u'klass']].from_codes
590590
return from_codes(codes=obj[u'codes'],
591591
categories=obj[u'categories'],
592-
ordered=obj[u'ordered'],
593-
name=obj[u'name'])
592+
ordered=obj[u'ordered'])
594593

595594
elif typ == u'series':
596595
dtype = dtype_for(obj[u'dtype'])

pandas/tests/io/test_pickle.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,8 @@ def python_unpickler(path):
265265

266266
def test_pickle_v0_14_1():
267267

268-
# we have the name warning
269-
# 10482
270-
with tm.assert_produces_warning(UserWarning):
271-
cat = pd.Categorical(values=['a', 'b', 'c'],
272-
categories=['a', 'b', 'c', 'd'],
273-
name='foobar', ordered=False)
268+
cat = pd.Categorical(values=['a', 'b', 'c'], ordered=False,
269+
categories=['a', 'b', 'c', 'd'])
274270
pickle_path = os.path.join(tm.get_data_path(),
275271
'categorical_0_14_1.pickle')
276272
# This code was executed once on v0.14.1 to generate the pickle:
@@ -286,12 +282,8 @@ def test_pickle_v0_15_2():
286282
# ordered -> _ordered
287283
# GH 9347
288284

289-
# we have the name warning
290-
# 10482
291-
with tm.assert_produces_warning(UserWarning):
292-
cat = pd.Categorical(values=['a', 'b', 'c'],
293-
categories=['a', 'b', 'c', 'd'],
294-
name='foobar', ordered=False)
285+
cat = pd.Categorical(values=['a', 'b', 'c'], ordered=False,
286+
categories=['a', 'b', 'c', 'd'])
295287
pickle_path = os.path.join(tm.get_data_path(),
296288
'categorical_0_15_2.pickle')
297289
# This code was executed once on v0.15.2 to generate the pickle:

pandas/tests/test_categorical.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ def test_print(self):
682682

683683
def test_big_print(self):
684684
factor = Categorical([0, 1, 2, 0, 1, 2] * 100, ['a', 'b', 'c'],
685-
name='cat', fastpath=True)
685+
fastpath=True)
686686
expected = ["[a, b, c, a, b, ..., b, c, a, b, c]", "Length: 600",
687687
"Categories (3, object): [a, b, c]"]
688688
expected = "\n".join(expected)
@@ -1635,15 +1635,6 @@ def test_deprecated_from_array(self):
16351635
with tm.assert_produces_warning(FutureWarning):
16361636
Categorical.from_array([0, 1])
16371637

1638-
def test_removed_names_produces_warning(self):
1639-
1640-
# 10482
1641-
with tm.assert_produces_warning(UserWarning):
1642-
Categorical([0, 1], name="a")
1643-
1644-
with tm.assert_produces_warning(UserWarning):
1645-
Categorical.from_codes([1, 2], ["a", "b", "c"], name="a")
1646-
16471638
def test_datetime_categorical_comparison(self):
16481639
dt_cat = pd.Categorical(
16491640
pd.date_range('2014-01-01', periods=3), ordered=True)

0 commit comments

Comments
 (0)