From d530db0eac4b0fed4eb6d78b657d7f7372671a6c Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Wed, 12 Oct 2016 16:13:38 -0500 Subject: [PATCH 01/16] Made it so that 0 was included in uint8 --- pandas/tools/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tools/util.py b/pandas/tools/util.py index fec56328c1721..b50bf9dc448bc 100644 --- a/pandas/tools/util.py +++ b/pandas/tools/util.py @@ -205,7 +205,7 @@ def to_numeric(arg, errors='raise', downcast=None): if downcast in ('integer', 'signed'): typecodes = np.typecodes['Integer'] - elif downcast == 'unsigned' and np.min(values) > 0: + elif downcast == 'unsigned' and np.min(values) >= 0: typecodes = np.typecodes['UnsignedInteger'] elif downcast == 'float': typecodes = np.typecodes['Float'] From f3bdcdcc55d75b4ad3a798c8862f4074dc270a74 Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Wed, 12 Oct 2016 18:49:19 -0500 Subject: [PATCH 02/16] Added a test to check uint8 with 0 --- pandas/tools/tests/test_util.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index 8c16308d79a31..e5286ccdbe2a4 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -391,6 +391,14 @@ def test_downcast(self): res = pd.to_numeric(data, downcast=downcast) tm.assert_numpy_array_equal(res, expected) + #check that 0 works as a unsigned downcast + + data = [0, 1, 2, 3] + res = pd.to_numeric(data, downcast=downcast) + expected = np.array(data, dtype=np.uint8) + tm.assert_numpy_array_equal(res, expected) + + # the smallest integer dtype need not be np.(u)int8 data = ['256', 257, 258] From 180d0ec2dbeee7d89ab703259b435d1b98607621 Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Wed, 12 Oct 2016 19:07:04 -0500 Subject: [PATCH 03/16] Added release note to issue 14401 resolve. --- doc/source/whatsnew/v0.19.1.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.19.1.txt b/doc/source/whatsnew/v0.19.1.txt index db5bd22393e64..17a7745091c30 100644 --- a/doc/source/whatsnew/v0.19.1.txt +++ b/doc/source/whatsnew/v0.19.1.txt @@ -58,4 +58,5 @@ Bug Fixes - Bug in ``df.groupby`` causing an ``AttributeError`` when grouping a single index frame by a column and the index level (:issue`14327`) - Bug in ``df.groupby`` where ``TypeError`` raised when ``pd.Grouper(key=...)`` is passed in a list (:issue:`14334`) - Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns`` - is not scalar and ``values`` is not specified (:issue:`14380`) \ No newline at end of file + is not scalar and ``values`` is not specified (:issue:`14380`) +- Bug in ``pd.to_numeric`` where a 0 was not unsigned on a downcast = 'unsigned' argument (:issue:`14401`) From 4794ca63037517e983cca4eb4fff6b0079f8b5bf Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Thu, 13 Oct 2016 20:42:36 -0500 Subject: [PATCH 04/16] Added tests for the max and min values of all dtypes to to_numeric --- pandas/tools/tests/test_util.py | 34 +++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index e5286ccdbe2a4..59f8d31104a61 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -391,14 +391,6 @@ def test_downcast(self): res = pd.to_numeric(data, downcast=downcast) tm.assert_numpy_array_equal(res, expected) - #check that 0 works as a unsigned downcast - - data = [0, 1, 2, 3] - res = pd.to_numeric(data, downcast=downcast) - expected = np.array(data, dtype=np.uint8) - tm.assert_numpy_array_equal(res, expected) - - # the smallest integer dtype need not be np.(u)int8 data = ['256', 257, 258] @@ -409,6 +401,32 @@ def test_downcast(self): res = pd.to_numeric(data, downcast=downcast) tm.assert_numpy_array_equal(res, expected) + # check that the smallest and largest values in each integer type pass to each type. + int8 = [-128, 127] + int8_Series = pd.to_numeric(int8, downcast = 'integer') + tm.assert_equal(int8_Series.dtype, 'int8') + int16 = [-32768, 32767] + int16_Series = pd.to_numeric(int16, downcast = 'integer') + tm.assert_equal(int16_Series.dtype, 'int16') + int32 = [-2147483648, 2147483647] + int32_Series = pd.to_numeric(int32, downcast = 'integer') + tm.assert_equal(int32_Series.dtype, 'int32') + int64 = [-9223372036854775808, 9223372036854775807] + int64_Series = pd.to_numeric(int64, downcast = 'integer') + tm.assert_equal(int64_Series.dtype, 'int64') + uint8 = [0, 255] + uint8_Series = pd.to_numeric(uint8, downcast = 'unsigned') + tm.assert_equal(uint8_Series.dtype, 'uint8') + uint16 = [0, 65535] + uint16_Series = pd.to_numeric(uint16, downcast = 'unsigned') + tm.assert_equal(uint16_Series.dtype, 'uint16') + uint32 = [0, 4294967295] + uint32_Series = pd.to_numeric(uint32, downcast = 'unsigned') + tm.assert_equal(uint32_Series.dtype, 'uint32') + # uint64 = [0, 18446744073709551615] + # uint64_Series = pd.to_numeric(uint64, downcast = 'unsigned') + # tm.assert_equal(uint64_Series.dtype, 'uint64') + if __name__ == '__main__': nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], exit=False) From 058697f7d0cead9f041d9f199eb879559eac15a5 Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Fri, 14 Oct 2016 20:18:47 -0500 Subject: [PATCH 05/16] Changed the tests so that it iterated through a dictionary. I also added a series of other tests that included making sure that a dtype shifted dtype once it reached the next value and once again edited the whatsnew. --- pandas/tools/tests/test_util.py | 78 +++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index 59f8d31104a61..856ed8431c548 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -402,30 +402,60 @@ def test_downcast(self): tm.assert_numpy_array_equal(res, expected) # check that the smallest and largest values in each integer type pass to each type. - int8 = [-128, 127] - int8_Series = pd.to_numeric(int8, downcast = 'integer') - tm.assert_equal(int8_Series.dtype, 'int8') - int16 = [-32768, 32767] - int16_Series = pd.to_numeric(int16, downcast = 'integer') - tm.assert_equal(int16_Series.dtype, 'int16') - int32 = [-2147483648, 2147483647] - int32_Series = pd.to_numeric(int32, downcast = 'integer') - tm.assert_equal(int32_Series.dtype, 'int32') - int64 = [-9223372036854775808, 9223372036854775807] - int64_Series = pd.to_numeric(int64, downcast = 'integer') - tm.assert_equal(int64_Series.dtype, 'int64') - uint8 = [0, 255] - uint8_Series = pd.to_numeric(uint8, downcast = 'unsigned') - tm.assert_equal(uint8_Series.dtype, 'uint8') - uint16 = [0, 65535] - uint16_Series = pd.to_numeric(uint16, downcast = 'unsigned') - tm.assert_equal(uint16_Series.dtype, 'uint16') - uint32 = [0, 4294967295] - uint32_Series = pd.to_numeric(uint32, downcast = 'unsigned') - tm.assert_equal(uint32_Series.dtype, 'uint32') - # uint64 = [0, 18446744073709551615] - # uint64_Series = pd.to_numeric(uint64, downcast = 'unsigned') - # tm.assert_equal(uint64_Series.dtype, 'uint64') + integer_dtype_min_max = { + 'int8': [np.iinfo(np.int8).min, np.iinfo(np.int8).max], + 'int16': [np.iinfo(np.int16).min, np.iinfo(np.int16).max], + 'int32': [np.iinfo(np.int32).min, np.iinfo(np.int32).max], + 'int64': [np.iinfo(np.int64).min, np.iinfo(np.int64).max] + } + + for dtype, min_max in integer_dtype_min_max.iteritems(): + series = pd.to_numeric(pd.Series(min_max), downcast = 'integer') + tm.assert_equal(series.dtype, dtype) + + + unsigned_dtype_min_max = { + 'uint8': [np.iinfo(np.uint8).min, np.iinfo(np.uint8).max], + 'uint16': [np.iinfo(np.uint16).min, np.iinfo(np.uint16).max], + 'uint32': [np.iinfo(np.uint32).min, np.iinfo(np.uint32).max], + # 'uint64': [np.iinfo(np.uint64).min, np.iinfo(np.uint64).max] + } + + for dtype, min_max in unsigned_dtype_min_max.iteritems(): + series = pd.to_numeric(pd.Series(min_max), downcast = 'unsigned') + tm.assert_equal(series.dtype, dtype) + + #check to see if the minimum number to shift integer types actually shifts + + integer_dtype_min_max_plus = { + 'int16': [np.iinfo(np.int8).min, np.iinfo(np.int8).max + 1], + 'int32': [np.iinfo(np.int16).min, np.iinfo(np.int16).max + 1], + 'int64': [np.iinfo(np.int32).min, np.iinfo(np.int32).max + 1], + } + + for dtype, min_max in integer_dtype_min_max_plus.iteritems(): + series = pd.to_numeric(pd.Series(min_max), downcast = 'integer') + tm.assert_equal(series.dtype, dtype) + + integer_dtype_min_max_minus = { + 'int16': [np.iinfo(np.int8).min - 1, np.iinfo(np.int16).max], + 'int32': [np.iinfo(np.int16).min - 1, np.iinfo(np.int32).max], + 'int64': [np.iinfo(np.int32).min - 1, np.iinfo(np.int64).max] + } + + for dtype, min_max in integer_dtype_min_max_minus.iteritems(): + series = pd.to_numeric(pd.Series(min_max), downcast = 'integer') + tm.assert_equal(series.dtype, dtype) + + unsigned_dtype_min_max_plus = { + 'uint16': [np.iinfo(np.uint8).min, np.iinfo(np.uint8).max + 1], + 'uint32': [np.iinfo(np.uint16).min, np.iinfo(np.uint16).max + 1], + # 'uint64': [np.iinfo(np.uint32).min, np.iinfo(np.uint32).max + 1], + } + + for dtype, min_max in unsigned_dtype_min_max_plus.iteritems(): + series = pd.to_numeric(pd.Series(min_max), downcast = 'unsigned') + tm.assert_equal(series.dtype, dtype) if __name__ == '__main__': nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], From 5a7457a3f254aa7fbc8227a4fb41689381a2241c Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Mon, 17 Oct 2016 18:20:05 -0500 Subject: [PATCH 06/16] Changed the test to work with python 3.x --- pandas/tools/tests/test_util.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index 856ed8431c548..54cfd1dacb87e 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -409,7 +409,7 @@ def test_downcast(self): 'int64': [np.iinfo(np.int64).min, np.iinfo(np.int64).max] } - for dtype, min_max in integer_dtype_min_max.iteritems(): + for dtype, min_max in integer_dtype_min_max.items(): series = pd.to_numeric(pd.Series(min_max), downcast = 'integer') tm.assert_equal(series.dtype, dtype) @@ -421,7 +421,7 @@ def test_downcast(self): # 'uint64': [np.iinfo(np.uint64).min, np.iinfo(np.uint64).max] } - for dtype, min_max in unsigned_dtype_min_max.iteritems(): + for dtype, min_max in unsigned_dtype_min_max.items(): series = pd.to_numeric(pd.Series(min_max), downcast = 'unsigned') tm.assert_equal(series.dtype, dtype) @@ -433,7 +433,7 @@ def test_downcast(self): 'int64': [np.iinfo(np.int32).min, np.iinfo(np.int32).max + 1], } - for dtype, min_max in integer_dtype_min_max_plus.iteritems(): + for dtype, min_max in integer_dtype_min_max_plus.items(): series = pd.to_numeric(pd.Series(min_max), downcast = 'integer') tm.assert_equal(series.dtype, dtype) @@ -443,7 +443,7 @@ def test_downcast(self): 'int64': [np.iinfo(np.int32).min - 1, np.iinfo(np.int64).max] } - for dtype, min_max in integer_dtype_min_max_minus.iteritems(): + for dtype, min_max in integer_dtype_min_max_minus.items(): series = pd.to_numeric(pd.Series(min_max), downcast = 'integer') tm.assert_equal(series.dtype, dtype) @@ -453,7 +453,7 @@ def test_downcast(self): # 'uint64': [np.iinfo(np.uint32).min, np.iinfo(np.uint32).max + 1], } - for dtype, min_max in unsigned_dtype_min_max_plus.iteritems(): + for dtype, min_max in unsigned_dtype_min_max_plus.items(): series = pd.to_numeric(pd.Series(min_max), downcast = 'unsigned') tm.assert_equal(series.dtype, dtype) From 5ae5066e2c76b45056677900c1cdcf4bd4264e8a Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Fri, 21 Oct 2016 19:40:40 -0500 Subject: [PATCH 07/16] Made the dictionaries into one list of sets. --- pandas/tools/tests/test_util.py | 74 ++++++++++----------------------- 1 file changed, 22 insertions(+), 52 deletions(-) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index 54cfd1dacb87e..e876efaa946e3 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -402,60 +402,30 @@ def test_downcast(self): tm.assert_numpy_array_equal(res, expected) # check that the smallest and largest values in each integer type pass to each type. - integer_dtype_min_max = { - 'int8': [np.iinfo(np.int8).min, np.iinfo(np.int8).max], - 'int16': [np.iinfo(np.int16).min, np.iinfo(np.int16).max], - 'int32': [np.iinfo(np.int32).min, np.iinfo(np.int32).max], - 'int64': [np.iinfo(np.int64).min, np.iinfo(np.int64).max] - } - - for dtype, min_max in integer_dtype_min_max.items(): - series = pd.to_numeric(pd.Series(min_max), downcast = 'integer') + dtype_downcast_min_max = [ + ('int8', 'integer', [np.iinfo(np.int8).min, np.iinfo(np.int8).max]), + ('int16', 'integer', [np.iinfo(np.int16).min, np.iinfo(np.int16).max]), + ('int32', 'integer', [np.iinfo(np.int32).min, np.iinfo(np.int32).max]), + ('int64', 'integer', [np.iinfo(np.int64).min, np.iinfo(np.int64).max]), + ('uint8', 'unsigned', [np.iinfo(np.uint8).min, np.iinfo(np.uint8).max]), + ('uint16', 'unsigned', [np.iinfo(np.uint16).min, np.iinfo(np.uint16).max]), + ('uint32', 'unsigned', [np.iinfo(np.uint32).min, np.iinfo(np.uint32).max]), + # ('uint64', 'unsigned', [np.iinfo(np.uint64).min, np.iinfo(np.uint64).max]), + ('int16', 'integer', [np.iinfo(np.int8).min, np.iinfo(np.int8).max + 1]), + ('int32', 'integer', [np.iinfo(np.int16).min, np.iinfo(np.int16).max + 1]), + ('int64', 'integer', [np.iinfo(np.int32).min, np.iinfo(np.int32).max + 1]), + ('int16', 'integer', [np.iinfo(np.int8).min - 1, np.iinfo(np.int16).max]), + ('int32', 'integer', [np.iinfo(np.int16).min - 1, np.iinfo(np.int32).max]), + ('int64', 'integer', [np.iinfo(np.int32).min - 1, np.iinfo(np.int64).max]), + ('uint16', 'unsigned', [np.iinfo(np.uint8).min, np.iinfo(np.uint8).max + 1]), + ('uint32', 'unsigned', [np.iinfo(np.uint16).min, np.iinfo(np.uint16).max + 1]), + # ('uint64', 'unsigned', [np.iinfo(np.uint32).min, np.iinfo(np.uint32).max + 1]), + ] + + for dtype, downcast, min_max in dtype_downcast_min_max: + series = pd.to_numeric(pd.Series(min_max), downcast = downcast) tm.assert_equal(series.dtype, dtype) - - unsigned_dtype_min_max = { - 'uint8': [np.iinfo(np.uint8).min, np.iinfo(np.uint8).max], - 'uint16': [np.iinfo(np.uint16).min, np.iinfo(np.uint16).max], - 'uint32': [np.iinfo(np.uint32).min, np.iinfo(np.uint32).max], - # 'uint64': [np.iinfo(np.uint64).min, np.iinfo(np.uint64).max] - } - - for dtype, min_max in unsigned_dtype_min_max.items(): - series = pd.to_numeric(pd.Series(min_max), downcast = 'unsigned') - tm.assert_equal(series.dtype, dtype) - - #check to see if the minimum number to shift integer types actually shifts - - integer_dtype_min_max_plus = { - 'int16': [np.iinfo(np.int8).min, np.iinfo(np.int8).max + 1], - 'int32': [np.iinfo(np.int16).min, np.iinfo(np.int16).max + 1], - 'int64': [np.iinfo(np.int32).min, np.iinfo(np.int32).max + 1], - } - - for dtype, min_max in integer_dtype_min_max_plus.items(): - series = pd.to_numeric(pd.Series(min_max), downcast = 'integer') - tm.assert_equal(series.dtype, dtype) - - integer_dtype_min_max_minus = { - 'int16': [np.iinfo(np.int8).min - 1, np.iinfo(np.int16).max], - 'int32': [np.iinfo(np.int16).min - 1, np.iinfo(np.int32).max], - 'int64': [np.iinfo(np.int32).min - 1, np.iinfo(np.int64).max] - } - - for dtype, min_max in integer_dtype_min_max_minus.items(): - series = pd.to_numeric(pd.Series(min_max), downcast = 'integer') - tm.assert_equal(series.dtype, dtype) - - unsigned_dtype_min_max_plus = { - 'uint16': [np.iinfo(np.uint8).min, np.iinfo(np.uint8).max + 1], - 'uint32': [np.iinfo(np.uint16).min, np.iinfo(np.uint16).max + 1], - # 'uint64': [np.iinfo(np.uint32).min, np.iinfo(np.uint32).max + 1], - } - - for dtype, min_max in unsigned_dtype_min_max_plus.items(): - series = pd.to_numeric(pd.Series(min_max), downcast = 'unsigned') - tm.assert_equal(series.dtype, dtype) if __name__ == '__main__': nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], From 615c16a5c307c67e93987164d7c95f977ac5167a Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Mon, 24 Oct 2016 16:16:17 -0500 Subject: [PATCH 08/16] Did some editing for some lint problems. --- pandas/tools/tests/test_util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index e876efaa946e3..9bb81dff0c571 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -422,8 +422,8 @@ def test_downcast(self): # ('uint64', 'unsigned', [np.iinfo(np.uint32).min, np.iinfo(np.uint32).max + 1]), ] - for dtype, downcast, min_max in dtype_downcast_min_max: - series = pd.to_numeric(pd.Series(min_max), downcast = downcast) + for dtype, downcast, min_max in dtype_downcast_min_max: + series = pd.to_numeric(pd.Series(min_max), downcast=downcast) tm.assert_equal(series.dtype, dtype) From 7940a04517eaaa925fbcec3d5b870af0f682f4b6 Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Mon, 24 Oct 2016 20:20:48 -0500 Subject: [PATCH 09/16] Revert "Added release note to issue 14401 resolve." This reverts commit 636de09cbe4ede7c1acfef91501f0d0f2c8794e6. Conflicts: doc/source/whatsnew/v0.19.1.txt --- doc/source/whatsnew/v0.19.1.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v0.19.1.txt b/doc/source/whatsnew/v0.19.1.txt index 17a7745091c30..ec007260954e3 100644 --- a/doc/source/whatsnew/v0.19.1.txt +++ b/doc/source/whatsnew/v0.19.1.txt @@ -60,3 +60,5 @@ Bug Fixes - Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns`` is not scalar and ``values`` is not specified (:issue:`14380`) - Bug in ``pd.to_numeric`` where a 0 was not unsigned on a downcast = 'unsigned' argument (:issue:`14401`) +- Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns`` + is not scalar and ``values`` is not specified (:issue:`14380`) From 8da173b7d01ccfd09861122e63f5369af4a803f5 Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Mon, 24 Oct 2016 20:33:35 -0500 Subject: [PATCH 10/16] Made the downcast limits test its own function. --- pandas/tools/tests/test_util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index 9bb81dff0c571..0fe2be5008dae 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -401,7 +401,8 @@ def test_downcast(self): res = pd.to_numeric(data, downcast=downcast) tm.assert_numpy_array_equal(res, expected) - # check that the smallest and largest values in each integer type pass to each type. + def test_downcast_limits(self): + # Test the limits of each downcast. Bug: #14401. dtype_downcast_min_max = [ ('int8', 'integer', [np.iinfo(np.int8).min, np.iinfo(np.int8).max]), ('int16', 'integer', [np.iinfo(np.int16).min, np.iinfo(np.int16).max]), From a64c5ab2fef2296e4ee982f2867295b46b6dc59b Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Fri, 4 Nov 2016 23:06:47 -0500 Subject: [PATCH 11/16] Screwed up the issue tracker again --- doc/source/whatsnew/v0.19.1.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/source/whatsnew/v0.19.1.txt b/doc/source/whatsnew/v0.19.1.txt index ec007260954e3..17a7745091c30 100644 --- a/doc/source/whatsnew/v0.19.1.txt +++ b/doc/source/whatsnew/v0.19.1.txt @@ -60,5 +60,3 @@ Bug Fixes - Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns`` is not scalar and ``values`` is not specified (:issue:`14380`) - Bug in ``pd.to_numeric`` where a 0 was not unsigned on a downcast = 'unsigned' argument (:issue:`14401`) -- Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns`` - is not scalar and ``values`` is not specified (:issue:`14380`) From 100fe4a59ba7f21aba404605c1c11ccc7646264d Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Mon, 14 Nov 2016 19:41:48 -0600 Subject: [PATCH 12/16] Fixed the lint issues. --- pandas/tools/tests/test_util.py | 42 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index 0fe2be5008dae..8e29b9daed799 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -4,6 +4,8 @@ import nose import numpy as np +from numpy import (iinfo, int8, int16, int32, int64, + uint8, uint16, uint32,) import pandas as pd from pandas import date_range, Index @@ -402,26 +404,28 @@ def test_downcast(self): tm.assert_numpy_array_equal(res, expected) def test_downcast_limits(self): - # Test the limits of each downcast. Bug: #14401. + # Test the limits of each downcast. Bug: #14401. + i = 'integer' + u = 'unsigned' dtype_downcast_min_max = [ - ('int8', 'integer', [np.iinfo(np.int8).min, np.iinfo(np.int8).max]), - ('int16', 'integer', [np.iinfo(np.int16).min, np.iinfo(np.int16).max]), - ('int32', 'integer', [np.iinfo(np.int32).min, np.iinfo(np.int32).max]), - ('int64', 'integer', [np.iinfo(np.int64).min, np.iinfo(np.int64).max]), - ('uint8', 'unsigned', [np.iinfo(np.uint8).min, np.iinfo(np.uint8).max]), - ('uint16', 'unsigned', [np.iinfo(np.uint16).min, np.iinfo(np.uint16).max]), - ('uint32', 'unsigned', [np.iinfo(np.uint32).min, np.iinfo(np.uint32).max]), - # ('uint64', 'unsigned', [np.iinfo(np.uint64).min, np.iinfo(np.uint64).max]), - ('int16', 'integer', [np.iinfo(np.int8).min, np.iinfo(np.int8).max + 1]), - ('int32', 'integer', [np.iinfo(np.int16).min, np.iinfo(np.int16).max + 1]), - ('int64', 'integer', [np.iinfo(np.int32).min, np.iinfo(np.int32).max + 1]), - ('int16', 'integer', [np.iinfo(np.int8).min - 1, np.iinfo(np.int16).max]), - ('int32', 'integer', [np.iinfo(np.int16).min - 1, np.iinfo(np.int32).max]), - ('int64', 'integer', [np.iinfo(np.int32).min - 1, np.iinfo(np.int64).max]), - ('uint16', 'unsigned', [np.iinfo(np.uint8).min, np.iinfo(np.uint8).max + 1]), - ('uint32', 'unsigned', [np.iinfo(np.uint16).min, np.iinfo(np.uint16).max + 1]), - # ('uint64', 'unsigned', [np.iinfo(np.uint32).min, np.iinfo(np.uint32).max + 1]), - ] + ('int8', i, [iinfo(int8).min, iinfo(int8).max]), + ('int16', i, [iinfo(int16).min, iinfo(int16).max]), + ('int32', i, [iinfo(int32).min, iinfo(int32).max]), + ('int64', i, [iinfo(int64).min, iinfo(int64).max]), + ('uint8', u, [iinfo(uint8).min, iinfo(uint8).max]), + ('uint16', u, [iinfo(uint16).min, iinfo(uint16).max]), + ('uint32', u, [iinfo(uint32).min, iinfo(uint32).max]), + # ('uint64', u, [iinfo(uint64).min, iinfo(uint64).max]), + ('int16', i, [iinfo(int8).min, iinfo(int8).max + 1]), + ('int32', i, [iinfo(int16).min, iinfo(int16).max + 1]), + ('int64', i, [iinfo(int32).min, iinfo(int32).max + 1]), + ('int16', i, [iinfo(int8).min - 1, iinfo(int16).max]), + ('int32', i, [iinfo(int16).min - 1, iinfo(int32).max]), + ('int64', i, [iinfo(int32).min - 1, iinfo(int64).max]), + ('uint16', u, [iinfo(uint8).min, iinfo(uint8).max + 1]), + ('uint32', u, [iinfo(uint16).min, iinfo(uint16).max + 1]), + # ('uint64', u, [iinfo(uint32).min, iinfo(uint32).max + 1]), + ] for dtype, downcast, min_max in dtype_downcast_min_max: series = pd.to_numeric(pd.Series(min_max), downcast=downcast) From 8685112fd35fc63984023d5158627ff4956dbf11 Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Mon, 14 Nov 2016 19:59:24 -0600 Subject: [PATCH 13/16] Added a test to make sure numpy is new enough. --- pandas/tools/tests/test_util.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index 8e29b9daed799..410d0c1ab3d4a 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -2,6 +2,7 @@ import locale import codecs import nose +from distutils.version import LooseVersion import numpy as np from numpy import (iinfo, int8, int16, int32, int64, @@ -405,6 +406,10 @@ def test_downcast(self): def test_downcast_limits(self): # Test the limits of each downcast. Bug: #14401. + # Check to make sure numpy is new enough to run this test. + if LooseVersion(np.__version__) <= LooseVersion('1.8.2'): + return + i = 'integer' u = 'unsigned' dtype_downcast_min_max = [ From 90eef2016c2de14fa224bdec670b2efaed146d73 Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Tue, 15 Nov 2016 15:23:45 -0600 Subject: [PATCH 14/16] Added correct version test and changed whatsnew --- doc/source/whatsnew/v0.19.1.txt | 1 - doc/source/whatsnew/v0.19.2.txt | 1 + pandas/tools/tests/test_util.py | 7 +++---- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v0.19.1.txt b/doc/source/whatsnew/v0.19.1.txt index 17a7745091c30..545b4380d9b75 100644 --- a/doc/source/whatsnew/v0.19.1.txt +++ b/doc/source/whatsnew/v0.19.1.txt @@ -59,4 +59,3 @@ Bug Fixes - Bug in ``df.groupby`` where ``TypeError`` raised when ``pd.Grouper(key=...)`` is passed in a list (:issue:`14334`) - Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns`` is not scalar and ``values`` is not specified (:issue:`14380`) -- Bug in ``pd.to_numeric`` where a 0 was not unsigned on a downcast = 'unsigned' argument (:issue:`14401`) diff --git a/doc/source/whatsnew/v0.19.2.txt b/doc/source/whatsnew/v0.19.2.txt index dc11dd17bfdd7..561c3e825dec6 100644 --- a/doc/source/whatsnew/v0.19.2.txt +++ b/doc/source/whatsnew/v0.19.2.txt @@ -25,3 +25,4 @@ Bug Fixes - compat with ``dateutil==2.6.0`` for testing (:issue:`14621`) - allow ``nanoseconds`` in ``Timestamp.replace`` kwargs (:issue:`14621`) +- Bug in ``pd.to_numeric`` where a 0 was not unsigned on a downcast = 'unsigned' argument (:issue:`14401`) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index 410d0c1ab3d4a..76c9a9c402775 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -2,14 +2,13 @@ import locale import codecs import nose -from distutils.version import LooseVersion import numpy as np from numpy import (iinfo, int8, int16, int32, int64, uint8, uint16, uint32,) import pandas as pd -from pandas import date_range, Index +from pandas import (date_range, Index, _np_version_under1p9) import pandas.util.testing as tm from pandas.tools.util import cartesian_product, to_numeric @@ -407,8 +406,8 @@ def test_downcast(self): def test_downcast_limits(self): # Test the limits of each downcast. Bug: #14401. # Check to make sure numpy is new enough to run this test. - if LooseVersion(np.__version__) <= LooseVersion('1.8.2'): - return + if _np_version_under1p9: + raise nose.SkipTest("Numpy version is under 1.9") i = 'integer' u = 'unsigned' From 5fc9976628a463565c6d60b51c2b98a81b0755e3 Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Wed, 16 Nov 2016 12:16:24 -0600 Subject: [PATCH 15/16] Added comments and edited the whatsnew. --- doc/source/whatsnew/v0.19.2.txt | 2 +- pandas/tools/tests/test_util.py | 37 +++++++++++++++++---------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/doc/source/whatsnew/v0.19.2.txt b/doc/source/whatsnew/v0.19.2.txt index 561c3e825dec6..19974f2973b03 100644 --- a/doc/source/whatsnew/v0.19.2.txt +++ b/doc/source/whatsnew/v0.19.2.txt @@ -25,4 +25,4 @@ Bug Fixes - compat with ``dateutil==2.6.0`` for testing (:issue:`14621`) - allow ``nanoseconds`` in ``Timestamp.replace`` kwargs (:issue:`14621`) -- Bug in ``pd.to_numeric`` where a 0 was not unsigned on a downcast = 'unsigned' argument (:issue:`14401`) +- Bug in ``pd.to_numeric`` where a 0 was not unsigned on a ``downcast = "unsigned"`` argument (:issue:`14401`) diff --git a/pandas/tools/tests/test_util.py b/pandas/tools/tests/test_util.py index 76c9a9c402775..f9647721e3c5b 100644 --- a/pandas/tools/tests/test_util.py +++ b/pandas/tools/tests/test_util.py @@ -4,8 +4,7 @@ import nose import numpy as np -from numpy import (iinfo, int8, int16, int32, int64, - uint8, uint16, uint32,) +from numpy import iinfo import pandas as pd from pandas import (date_range, Index, _np_version_under1p9) @@ -412,23 +411,25 @@ def test_downcast_limits(self): i = 'integer' u = 'unsigned' dtype_downcast_min_max = [ - ('int8', i, [iinfo(int8).min, iinfo(int8).max]), - ('int16', i, [iinfo(int16).min, iinfo(int16).max]), - ('int32', i, [iinfo(int32).min, iinfo(int32).max]), - ('int64', i, [iinfo(int64).min, iinfo(int64).max]), - ('uint8', u, [iinfo(uint8).min, iinfo(uint8).max]), - ('uint16', u, [iinfo(uint16).min, iinfo(uint16).max]), - ('uint32', u, [iinfo(uint32).min, iinfo(uint32).max]), + ('int8', i, [iinfo(np.int8).min, iinfo(np.int8).max]), + ('int16', i, [iinfo(np.int16).min, iinfo(np.int16).max]), + ('int32', i, [iinfo(np.int32).min, iinfo(np.int32).max]), + ('int64', i, [iinfo(np.int64).min, iinfo(np.int64).max]), + ('uint8', u, [iinfo(np.uint8).min, iinfo(np.uint8).max]), + ('uint16', u, [iinfo(np.uint16).min, iinfo(np.uint16).max]), + ('uint32', u, [iinfo(np.uint32).min, iinfo(np.uint32).max]), + # Test will be skipped until there is more uint64 support. # ('uint64', u, [iinfo(uint64).min, iinfo(uint64).max]), - ('int16', i, [iinfo(int8).min, iinfo(int8).max + 1]), - ('int32', i, [iinfo(int16).min, iinfo(int16).max + 1]), - ('int64', i, [iinfo(int32).min, iinfo(int32).max + 1]), - ('int16', i, [iinfo(int8).min - 1, iinfo(int16).max]), - ('int32', i, [iinfo(int16).min - 1, iinfo(int32).max]), - ('int64', i, [iinfo(int32).min - 1, iinfo(int64).max]), - ('uint16', u, [iinfo(uint8).min, iinfo(uint8).max + 1]), - ('uint32', u, [iinfo(uint16).min, iinfo(uint16).max + 1]), - # ('uint64', u, [iinfo(uint32).min, iinfo(uint32).max + 1]), + ('int16', i, [iinfo(np.int8).min, iinfo(np.int8).max + 1]), + ('int32', i, [iinfo(np.int16).min, iinfo(np.int16).max + 1]), + ('int64', i, [iinfo(np.int32).min, iinfo(np.int32).max + 1]), + ('int16', i, [iinfo(np.int8).min - 1, iinfo(np.int16).max]), + ('int32', i, [iinfo(np.int16).min - 1, iinfo(np.int32).max]), + ('int64', i, [iinfo(np.int32).min - 1, iinfo(np.int64).max]), + ('uint16', u, [iinfo(np.uint8).min, iinfo(np.uint8).max + 1]), + ('uint32', u, [iinfo(np.uint16).min, iinfo(np.uint16).max + 1]), + # Test will be skipped until there is more uint64 support. + # ('uint64', u, [iinfo(np.uint32).min, iinfo(np.uint32).max + 1]), ] for dtype, downcast, min_max in dtype_downcast_min_max: From 07264cd9bfb3b49b8a1b9769991a155c7b92cdde Mon Sep 17 00:00:00 2001 From: Nicholas Ver Halen Date: Wed, 16 Nov 2016 13:53:29 -0600 Subject: [PATCH 16/16] Revert --- doc/source/whatsnew/v0.19.1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.19.1.txt b/doc/source/whatsnew/v0.19.1.txt index 545b4380d9b75..db5bd22393e64 100644 --- a/doc/source/whatsnew/v0.19.1.txt +++ b/doc/source/whatsnew/v0.19.1.txt @@ -58,4 +58,4 @@ Bug Fixes - Bug in ``df.groupby`` causing an ``AttributeError`` when grouping a single index frame by a column and the index level (:issue`14327`) - Bug in ``df.groupby`` where ``TypeError`` raised when ``pd.Grouper(key=...)`` is passed in a list (:issue:`14334`) - Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns`` - is not scalar and ``values`` is not specified (:issue:`14380`) + is not scalar and ``values`` is not specified (:issue:`14380`) \ No newline at end of file