@@ -402,30 +402,60 @@ def test_downcast(self):
402
402
tm .assert_numpy_array_equal (res , expected )
403
403
404
404
# check that the smallest and largest values in each integer type pass to each type.
405
- int8 = [- 128 , 127 ]
406
- int8_Series = pd .to_numeric (int8 , downcast = 'integer' )
407
- tm .assert_equal (int8_Series .dtype , 'int8' )
408
- int16 = [- 32768 , 32767 ]
409
- int16_Series = pd .to_numeric (int16 , downcast = 'integer' )
410
- tm .assert_equal (int16_Series .dtype , 'int16' )
411
- int32 = [- 2147483648 , 2147483647 ]
412
- int32_Series = pd .to_numeric (int32 , downcast = 'integer' )
413
- tm .assert_equal (int32_Series .dtype , 'int32' )
414
- int64 = [- 9223372036854775808 , 9223372036854775807 ]
415
- int64_Series = pd .to_numeric (int64 , downcast = 'integer' )
416
- tm .assert_equal (int64_Series .dtype , 'int64' )
417
- uint8 = [0 , 255 ]
418
- uint8_Series = pd .to_numeric (uint8 , downcast = 'unsigned' )
419
- tm .assert_equal (uint8_Series .dtype , 'uint8' )
420
- uint16 = [0 , 65535 ]
421
- uint16_Series = pd .to_numeric (uint16 , downcast = 'unsigned' )
422
- tm .assert_equal (uint16_Series .dtype , 'uint16' )
423
- uint32 = [0 , 4294967295 ]
424
- uint32_Series = pd .to_numeric (uint32 , downcast = 'unsigned' )
425
- tm .assert_equal (uint32_Series .dtype , 'uint32' )
426
- # uint64 = [0, 18446744073709551615]
427
- # uint64_Series = pd.to_numeric(uint64, downcast = 'unsigned')
428
- # tm.assert_equal(uint64_Series.dtype, 'uint64')
405
+ integer_dtype_min_max = {
406
+ 'int8' : [np .iinfo (np .int8 ).min , np .iinfo (np .int8 ).max ],
407
+ 'int16' : [np .iinfo (np .int16 ).min , np .iinfo (np .int16 ).max ],
408
+ 'int32' : [np .iinfo (np .int32 ).min , np .iinfo (np .int32 ).max ],
409
+ 'int64' : [np .iinfo (np .int64 ).min , np .iinfo (np .int64 ).max ]
410
+ }
411
+
412
+ for dtype , min_max in integer_dtype_min_max .iteritems ():
413
+ series = pd .to_numeric (pd .Series (min_max ), downcast = 'integer' )
414
+ tm .assert_equal (series .dtype , dtype )
415
+
416
+
417
+ unsigned_dtype_min_max = {
418
+ 'uint8' : [np .iinfo (np .uint8 ).min , np .iinfo (np .uint8 ).max ],
419
+ 'uint16' : [np .iinfo (np .uint16 ).min , np .iinfo (np .uint16 ).max ],
420
+ 'uint32' : [np .iinfo (np .uint32 ).min , np .iinfo (np .uint32 ).max ],
421
+ # 'uint64': [np.iinfo(np.uint64).min, np.iinfo(np.uint64).max]
422
+ }
423
+
424
+ for dtype , min_max in unsigned_dtype_min_max .iteritems ():
425
+ series = pd .to_numeric (pd .Series (min_max ), downcast = 'unsigned' )
426
+ tm .assert_equal (series .dtype , dtype )
427
+
428
+ #check to see if the minimum number to shift integer types actually shifts
429
+
430
+ integer_dtype_min_max_plus = {
431
+ 'int16' : [np .iinfo (np .int8 ).min , np .iinfo (np .int8 ).max + 1 ],
432
+ 'int32' : [np .iinfo (np .int16 ).min , np .iinfo (np .int16 ).max + 1 ],
433
+ 'int64' : [np .iinfo (np .int32 ).min , np .iinfo (np .int32 ).max + 1 ],
434
+ }
435
+
436
+ for dtype , min_max in integer_dtype_min_max_plus .iteritems ():
437
+ series = pd .to_numeric (pd .Series (min_max ), downcast = 'integer' )
438
+ tm .assert_equal (series .dtype , dtype )
439
+
440
+ integer_dtype_min_max_minus = {
441
+ 'int16' : [np .iinfo (np .int8 ).min - 1 , np .iinfo (np .int16 ).max ],
442
+ 'int32' : [np .iinfo (np .int16 ).min - 1 , np .iinfo (np .int32 ).max ],
443
+ 'int64' : [np .iinfo (np .int32 ).min - 1 , np .iinfo (np .int64 ).max ]
444
+ }
445
+
446
+ for dtype , min_max in integer_dtype_min_max_minus .iteritems ():
447
+ series = pd .to_numeric (pd .Series (min_max ), downcast = 'integer' )
448
+ tm .assert_equal (series .dtype , dtype )
449
+
450
+ unsigned_dtype_min_max_plus = {
451
+ 'uint16' : [np .iinfo (np .uint8 ).min , np .iinfo (np .uint8 ).max + 1 ],
452
+ 'uint32' : [np .iinfo (np .uint16 ).min , np .iinfo (np .uint16 ).max + 1 ],
453
+ # 'uint64': [np.iinfo(np.uint32).min, np.iinfo(np.uint32).max + 1],
454
+ }
455
+
456
+ for dtype , min_max in unsigned_dtype_min_max_plus .iteritems ():
457
+ series = pd .to_numeric (pd .Series (min_max ), downcast = 'unsigned' )
458
+ tm .assert_equal (series .dtype , dtype )
429
459
430
460
if __name__ == '__main__' :
431
461
nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
0 commit comments