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 gh-10632
  • Loading branch information
gfyoung committed Mar 11, 2017
1 parent 026e748 commit 874ef05
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 39 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ Other API Changes
- ``pandas.api.types.is_datetime64_ns_dtype`` will now report ``True`` on a tz-aware dtype, similar to ``pandas.api.types.is_datetime64_any_dtype``
- ``DataFrame.asof()`` will return a null filled ``Series`` instead the scalar ``NaN`` if a match is not found (:issue:`15118`)
- Reorganization of timeseries development tests (:issue:`14854`)
- The ``Categorical`` constructor has dropped the ``name`` parameter (:issue:`10632`)
- Specific support for ``copy.copy()`` and ``copy.deepcopy()`` functions on NDFrame objects (:issue:`15444`)
- ``Series.sort_values()`` accepts a one element list of bool for consistency with the behavior of ``DataFrame.sort_values()`` (:issue:`15604`)
- ``.merge()`` and ``.join()`` on ``category`` dtype columns will now preserve the category dtype when possible (:issue:`10409`)
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 874ef05

Please sign in to comment.