@@ -159,8 +159,8 @@ def test_memory_usage(self):
159
159
class Ops :
160
160
def _allow_na_ops (self , obj ):
161
161
"""Whether to skip test cases including NaN"""
162
- if isinstance (obj , Index ) and ( obj .is_boolean () or not obj ._can_hold_na ) :
163
- # don't test boolean / int64 index
162
+ if ( isinstance (obj , Index ) and obj .is_boolean ()) or not obj ._can_hold_na :
163
+ # don't test boolean / integer dtypes
164
164
return False
165
165
return True
166
166
@@ -187,7 +187,24 @@ def setup_method(self, method):
187
187
types = ["bool" , "int" , "float" , "dt" , "dt_tz" , "period" , "string" , "unicode" ]
188
188
self .indexes = [getattr (self , "{}_index" .format (t )) for t in types ]
189
189
self .series = [getattr (self , "{}_series" .format (t )) for t in types ]
190
- self .objs = self .indexes + self .series
190
+
191
+ # To test narrow dtypes, we use narrower *data* elements, not *index* elements
192
+ index = self .int_index
193
+ self .float32_series = Series (arr .astype (np .float32 ), index = index , name = "a" )
194
+
195
+ arr_int = np .random .choice (10 , size = 10 , replace = False )
196
+ self .int8_series = Series (arr_int .astype (np .int8 ), index = index , name = "a" )
197
+ self .int16_series = Series (arr_int .astype (np .int16 ), index = index , name = "a" )
198
+ self .int32_series = Series (arr_int .astype (np .int32 ), index = index , name = "a" )
199
+
200
+ self .uint8_series = Series (arr_int .astype (np .uint8 ), index = index , name = "a" )
201
+ self .uint16_series = Series (arr_int .astype (np .uint16 ), index = index , name = "a" )
202
+ self .uint32_series = Series (arr_int .astype (np .uint32 ), index = index , name = "a" )
203
+
204
+ nrw_types = ["float32" , "int8" , "int16" , "int32" , "uint8" , "uint16" , "uint32" ]
205
+ self .narrow_series = [getattr (self , "{}_series" .format (t )) for t in nrw_types ]
206
+
207
+ self .objs = self .indexes + self .series + self .narrow_series
191
208
192
209
def check_ops_properties (self , props , filter = None , ignore_failures = False ):
193
210
for op in props :
@@ -385,6 +402,7 @@ def test_value_counts_unique_nunique(self):
385
402
if isinstance (o , Index ):
386
403
assert isinstance (result , o .__class__ )
387
404
tm .assert_index_equal (result , orig )
405
+ assert result .dtype == orig .dtype
388
406
elif is_datetime64tz_dtype (o ):
389
407
# datetimetz Series returns array of Timestamp
390
408
assert result [0 ] == orig [0 ]
@@ -396,6 +414,7 @@ def test_value_counts_unique_nunique(self):
396
414
)
397
415
else :
398
416
tm .assert_numpy_array_equal (result , orig .values )
417
+ assert result .dtype == orig .dtype
399
418
400
419
assert o .nunique () == len (np .unique (o .values ))
401
420
@@ -904,7 +923,7 @@ def test_fillna(self):
904
923
905
924
expected = [fill_value ] * 2 + list (values [2 :])
906
925
907
- expected = klass (expected )
926
+ expected = klass (expected , dtype = orig . dtype )
908
927
o = klass (values )
909
928
910
929
# check values has the same dtype as the original
0 commit comments