Skip to content

Commit

Permalink
API: Drop the name parameter from Categorical
Browse files Browse the repository at this point in the history
Deprecated in 0.17.0

xref #10632

Author: gfyoung <gfyoung17@gmail.com>

Closes #15654 from gfyoung/categorical-name-drop and squashes the following commits:

7e1e7d8 [gfyoung] API: Drop the name parameter from Categorical
  • Loading branch information
gfyoung authored and jreback committed Mar 11, 2017
1 parent 026e748 commit aa53e4f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 40 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ Removal of prior version deprecations/changes
- The deprecated ``irow``, ``icol``, ``iget`` and ``iget_value`` methods are removed
in favor of ``iloc`` and ``iat`` as explained :ref:`here <whatsnew_0170.deprecations>` (:issue:`10711`).
- The deprecated ``DataFrame.iterkv()`` has been removed in favor of ``DataFrame.iteritems()`` (:issue:`10711`)

- The ``Categorical`` constructor has dropped the ``name`` parameter (:issue:`10632`)

.. _whatsnew_0200.performance:

Expand Down
17 changes: 2 additions & 15 deletions pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ class Categorical(PandasObject):
__array_priority__ = 1000
_typ = 'categorical'

def __init__(self, values, categories=None, ordered=False,
name=None, fastpath=False):
def __init__(self, values, categories=None, ordered=False, fastpath=False):

self._validate_ordered(ordered)

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

if name is not None:
msg = ("the 'name' keyword is removed, use 'name' with consumers "
"of the categorical instead (e.g. 'Series(cat, "
"name=\"something\")'")
warn(msg, UserWarning, stacklevel=2)

# sanitize input
if is_categorical_dtype(values):

Expand Down Expand Up @@ -431,7 +424,7 @@ def from_array(cls, data, **kwargs):
return cls(data, **kwargs)

@classmethod
def from_codes(cls, codes, categories, ordered=False, name=None):
def from_codes(cls, codes, categories, ordered=False):
"""
Make a Categorical type from codes and categories arrays.
Expand All @@ -454,12 +447,6 @@ def from_codes(cls, codes, categories, ordered=False, name=None):
categorical. If not given, the resulting categorical will be
unordered.
"""
if name is not None:
msg = ("the 'name' keyword is removed, use 'name' with consumers "
"of the categorical instead (e.g. 'Series(cat, "
"name=\"something\")'")
warn(msg, UserWarning, stacklevel=2)

try:
codes = np.asarray(codes, np.int64)
except:
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,7 @@ def decode(obj):
from_codes = globals()[obj[u'klass']].from_codes
return from_codes(codes=obj[u'codes'],
categories=obj[u'categories'],
ordered=obj[u'ordered'],
name=obj[u'name'])
ordered=obj[u'ordered'])

elif typ == u'series':
dtype = dtype_for(obj[u'dtype'])
Expand Down
16 changes: 4 additions & 12 deletions pandas/tests/io/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,8 @@ def python_unpickler(path):

def test_pickle_v0_14_1():

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

# we have the name warning
# 10482
with tm.assert_produces_warning(UserWarning):
cat = pd.Categorical(values=['a', 'b', 'c'],
categories=['a', 'b', 'c', 'd'],
name='foobar', ordered=False)
cat = pd.Categorical(values=['a', 'b', 'c'], ordered=False,
categories=['a', 'b', 'c', 'd'])
pickle_path = os.path.join(tm.get_data_path(),
'categorical_0_15_2.pickle')
# This code was executed once on v0.15.2 to generate the pickle:
Expand Down
11 changes: 1 addition & 10 deletions pandas/tests/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ def test_print(self):

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

def test_removed_names_produces_warning(self):

# 10482
with tm.assert_produces_warning(UserWarning):
Categorical([0, 1], name="a")

with tm.assert_produces_warning(UserWarning):
Categorical.from_codes([1, 2], ["a", "b", "c"], name="a")

def test_datetime_categorical_comparison(self):
dt_cat = pd.Categorical(
pd.date_range('2014-01-01', periods=3), ordered=True)
Expand Down

0 comments on commit aa53e4f

Please sign in to comment.