Skip to content

Commit a7c2985

Browse files
committed
fixups
1 parent 24b19a8 commit a7c2985

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

pandas/core/dtypes/dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def __eq__(self, other):
199199
return hash(self) == hash(other)
200200

201201
def __unicode__(self):
202-
tpl = 'CategoricalDtype({}, ordered={})'
202+
tpl = 'CategoricalDtype({}ordered={})'
203203
if self.categories is None:
204204
data = "None"
205205
else:

pandas/core/internals.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,14 @@ def is_categorical_astype(self, dtype):
137137
validate that we have a astypeable to categorical,
138138
returns a boolean if we are a categorical
139139
"""
140-
if is_categorical_dtype(dtype):
141-
if dtype == CategoricalDtype():
142-
return True
143-
144-
elif dtype is Categorical:
140+
if dtype is Categorical or dtype is CategoricalDtype:
145141
# this is a pd.Categorical, but is not
146142
# a valid type for astypeing
147143
raise TypeError("invalid type {0} for astype".format(dtype))
148144

145+
elif is_categorical_dtype(dtype):
146+
return True
147+
149148
return False
150149

151150
def external_values(self, dtype=None):
@@ -491,7 +490,9 @@ def _astype(self, dtype, copy=False, errors='raise', values=None,
491490
if (('categories' in kwargs or 'ordered' in kwargs) and
492491
isinstance(dtype, CategoricalDtype)):
493492
raise TypeError("Cannot specify a CategoricalDtype and also "
494-
"`categories` or `ordered`")
493+
"`categories` or `ordered`. Use "
494+
"`dtype=CategoricalDtype(categories, ordered)`"
495+
" instead.")
495496
kwargs = kwargs.copy()
496497
categories = getattr(dtype, 'categories', None)
497498
ordered = getattr(dtype, 'ordered', False)

pandas/tests/series/test_analytics.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1724,7 +1724,6 @@ class TestNLargestNSmallest(object):
17241724
# not supported on some archs
17251725
# Series([3., 2, 1, 2, 5], dtype='complex256'),
17261726
Series([3., 2, 1, 2, 5], dtype='complex128'),
1727-
Series(list('abcde'), dtype='category'),
17281727
Series(list('abcde'))])
17291728
def test_error(self, r):
17301729
dt = r.dtype
@@ -1736,6 +1735,16 @@ def test_error(self, r):
17361735
with tm.assert_raises_regex(TypeError, msg):
17371736
method(arg)
17381737

1738+
def test_error_categorical_dtype(self):
1739+
# same as test_error, but regex hard to escape properly
1740+
msg = ("Cannot use method 'n(larg|small)est' with dtype "
1741+
"CategoricalDtype.+")
1742+
with tm.assert_raises_regex(TypeError, msg):
1743+
Series(list('ab'), dtype='category').nlargest(2)
1744+
1745+
with tm.assert_raises_regex(TypeError, msg):
1746+
Series(list('ab'), dtype='category').nsmallest(2)
1747+
17391748
@pytest.mark.parametrize(
17401749
"s",
17411750
[v for k, v in s_main_dtypes().iteritems()])

pandas/tests/test_config.py

-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import pytest
33

44
import pandas as pd
5-
import pandas.util.testing as tm
65

76
import warnings
87

@@ -429,8 +428,3 @@ def test_option_context_scope(self):
429428

430429
# Ensure the current context is reset
431430
assert self.cf.get_option(option_name) == original_value
432-
433-
def test_html_border_deprecated(self):
434-
with tm.assert_produces_warning(FutureWarning):
435-
with pd.option_context("html.border", 0):
436-
pass

0 commit comments

Comments
 (0)