Skip to content

Commit ef35e19

Browse files
author
Nicholas Ver Halen
committed
Added tests for the max and min values of all dtypes to to_numeric
1 parent cc278ff commit ef35e19

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

pandas/tools/tests/test_util.py

+26-8
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,6 @@ def test_downcast(self):
391391
res = pd.to_numeric(data, downcast=downcast)
392392
tm.assert_numpy_array_equal(res, expected)
393393

394-
#check that 0 works as a unsigned downcast
395-
396-
data = [0, 1, 2, 3]
397-
res = pd.to_numeric(data, downcast=downcast)
398-
expected = np.array(data, dtype=np.uint8)
399-
tm.assert_numpy_array_equal(res, expected)
400-
401-
402394
# the smallest integer dtype need not be np.(u)int8
403395
data = ['256', 257, 258]
404396

@@ -409,6 +401,32 @@ def test_downcast(self):
409401
res = pd.to_numeric(data, downcast=downcast)
410402
tm.assert_numpy_array_equal(res, expected)
411403

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')
429+
412430
if __name__ == '__main__':
413431
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
414432
exit=False)

0 commit comments

Comments
 (0)