File tree 2 files changed +4
-9
lines changed
2 files changed +4
-9
lines changed Original file line number Diff line number Diff line change @@ -141,6 +141,7 @@ def is_categorical_astype(self, dtype):
141
141
if dtype == CategoricalDtype ():
142
142
return True
143
143
144
+ elif dtype is Categorical :
144
145
# this is a pd.Categorical, but is not
145
146
# a valid type for astypeing
146
147
raise TypeError ("invalid type {0} for astype" .format (dtype ))
Original file line number Diff line number Diff line change @@ -4149,12 +4149,6 @@ def f():
4149
4149
df = pd .DataFrame ({'a' : pd .Categorical (idx )})
4150
4150
tm .assert_frame_equal (df .fillna (value = pd .NaT ), df )
4151
4151
4152
- def test_astype_new (self ):
4153
- s = self .cat ['value_group' ]
4154
- r1 = s .astype ('object' )
4155
- r2 = r1 .astype ('category' )
4156
- tm .assert_series_equal (r2 , s )
4157
-
4158
4152
def test_astype_to_other (self ):
4159
4153
4160
4154
s = self .cat ['value_group' ]
@@ -4197,9 +4191,9 @@ def cmp(a, b):
4197
4191
tm .assert_series_equal (result , s , check_categorical = False )
4198
4192
4199
4193
# invalid conversion (these are NOT a dtype)
4200
- # for invalid in [lambda x: x.astype(pd.Categorical),
4201
- # lambda x: x.astype('object').astype(pd.Categorical)]:
4202
- # pytest.raises(TypeError, lambda: invalid(s))
4194
+ for invalid in [lambda x : x .astype (pd .Categorical ),
4195
+ lambda x : x .astype ('object' ).astype (pd .Categorical )]:
4196
+ pytest .raises (TypeError , lambda : invalid (s ))
4203
4197
4204
4198
def test_astype_categorical (self ):
4205
4199
You can’t perform that action at this time.
0 commit comments