From c6e64b115ea6188889724e0d5be070d7447f71b3 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Wed, 23 Sep 2020 15:13:06 -0500 Subject: [PATCH 1/3] TST: 32bit dtype compat #36579 --- pandas/tests/indexes/period/test_indexing.py | 4 +++- pandas/tests/indexes/test_base.py | 4 +++- pandas/tests/test_algos.py | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pandas/tests/indexes/period/test_indexing.py b/pandas/tests/indexes/period/test_indexing.py index f42499147cdbb..6d26a21b82468 100644 --- a/pandas/tests/indexes/period/test_indexing.py +++ b/pandas/tests/indexes/period/test_indexing.py @@ -5,6 +5,7 @@ import pytest from pandas._libs.tslibs import period as libperiod +from pandas.compat import IS64 from pandas.errors import InvalidIndexError import pandas as pd @@ -450,7 +451,8 @@ def test_get_indexer_non_unique(self): result = idx1.get_indexer_non_unique(idx2) expected_indexer = np.array([1, 0, 2, -1, -1], dtype=np.intp) - expected_missing = np.array([2, 3], dtype=np.int64) + expected_dtype = np.int64 if IS64 else np.int32 + expected_missing = np.array([2, 3], dtype=expected_dtype) tm.assert_numpy_array_equal(result[0], expected_indexer) tm.assert_numpy_array_equal(result[1], expected_missing) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index f811bd579aaaa..b64cd78e2cf0a 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -11,6 +11,7 @@ import pandas._config.config as cf from pandas._libs.tslib import Timestamp +from pandas.compat import IS64 from pandas.compat.numpy import np_datetime64_compat from pandas.util._test_decorators import async_mark @@ -2607,7 +2608,8 @@ def construct(dtype): ex1 = np.array([0, 3, 1, 4, 2, 5] * 2, dtype=np.intp) ex2 = np.array([], dtype=np.intp) tm.assert_numpy_array_equal(result[0], ex1) - tm.assert_numpy_array_equal(result[1], ex2.astype(np.int64)) + expected_dtype = np.int64 if IS64 else np.int32 + tm.assert_numpy_array_equal(result[1], ex2.astype(expected_dtype)) else: no_matches = np.array([-1] * 6, dtype=np.intp) diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 6102f43f4db6a..96ede2eac1de6 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -1545,7 +1545,8 @@ def test_lookup_nan(self, writable): xs.setflags(write=writable) m = ht.Float64HashTable() m.map_locations(xs) - tm.assert_numpy_array_equal(m.lookup(xs), np.arange(len(xs), dtype=np.int64)) + expected_dtype = np.int64 if IS64 else np.int32 + tm.assert_numpy_array_equal(m.lookup(xs), np.arange(len(xs), dtype=expected_dtype)) def test_add_signed_zeros(self): # GH 21866 inconsistent hash-function for float64 @@ -1578,7 +1579,8 @@ def test_lookup_overflow(self, writable): xs.setflags(write=writable) m = ht.UInt64HashTable() m.map_locations(xs) - tm.assert_numpy_array_equal(m.lookup(xs), np.arange(len(xs), dtype=np.int64)) + expected_dtype = np.int64 if IS64 else np.int32 + tm.assert_numpy_array_equal(m.lookup(xs), np.arange(len(xs), dtype=expected_dtype)) def test_get_unique(self): s = Series([1, 2, 2 ** 63, 2 ** 63], dtype=np.uint64) From aa61db374fb03afdbe8580a5625a49a35e3cd5cd Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Wed, 23 Sep 2020 15:16:40 -0500 Subject: [PATCH 2/3] TST: 32bit dtype compat #36579 --- pandas/tests/test_algos.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index 96ede2eac1de6..ad08440ecd111 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -1546,7 +1546,9 @@ def test_lookup_nan(self, writable): m = ht.Float64HashTable() m.map_locations(xs) expected_dtype = np.int64 if IS64 else np.int32 - tm.assert_numpy_array_equal(m.lookup(xs), np.arange(len(xs), dtype=expected_dtype)) + tm.assert_numpy_array_equal( + m.lookup(xs), np.arange(len(xs), dtype=expected_dtype) + ) def test_add_signed_zeros(self): # GH 21866 inconsistent hash-function for float64 @@ -1580,7 +1582,9 @@ def test_lookup_overflow(self, writable): m = ht.UInt64HashTable() m.map_locations(xs) expected_dtype = np.int64 if IS64 else np.int32 - tm.assert_numpy_array_equal(m.lookup(xs), np.arange(len(xs), dtype=expected_dtype)) + tm.assert_numpy_array_equal( + m.lookup(xs), np.arange(len(xs), dtype=expected_dtype) + ) def test_get_unique(self): s = Series([1, 2, 2 ** 63, 2 ** 63], dtype=np.uint64) From b74894a8d1e8aea72a50d30e44f8aa549bb4944c Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Wed, 23 Sep 2020 21:09:47 -0500 Subject: [PATCH 3/3] TST: use np.intp #36579 --- pandas/tests/indexes/period/test_indexing.py | 4 +--- pandas/tests/indexes/test_base.py | 4 +--- pandas/tests/test_algos.py | 10 ++-------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/pandas/tests/indexes/period/test_indexing.py b/pandas/tests/indexes/period/test_indexing.py index 6d26a21b82468..85a01f1c5278c 100644 --- a/pandas/tests/indexes/period/test_indexing.py +++ b/pandas/tests/indexes/period/test_indexing.py @@ -5,7 +5,6 @@ import pytest from pandas._libs.tslibs import period as libperiod -from pandas.compat import IS64 from pandas.errors import InvalidIndexError import pandas as pd @@ -451,8 +450,7 @@ def test_get_indexer_non_unique(self): result = idx1.get_indexer_non_unique(idx2) expected_indexer = np.array([1, 0, 2, -1, -1], dtype=np.intp) - expected_dtype = np.int64 if IS64 else np.int32 - expected_missing = np.array([2, 3], dtype=expected_dtype) + expected_missing = np.array([2, 3], dtype=np.intp) tm.assert_numpy_array_equal(result[0], expected_indexer) tm.assert_numpy_array_equal(result[1], expected_missing) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index b64cd78e2cf0a..7cafdb61fcb31 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -11,7 +11,6 @@ import pandas._config.config as cf from pandas._libs.tslib import Timestamp -from pandas.compat import IS64 from pandas.compat.numpy import np_datetime64_compat from pandas.util._test_decorators import async_mark @@ -2608,8 +2607,7 @@ def construct(dtype): ex1 = np.array([0, 3, 1, 4, 2, 5] * 2, dtype=np.intp) ex2 = np.array([], dtype=np.intp) tm.assert_numpy_array_equal(result[0], ex1) - expected_dtype = np.int64 if IS64 else np.int32 - tm.assert_numpy_array_equal(result[1], ex2.astype(expected_dtype)) + tm.assert_numpy_array_equal(result[1], ex2) else: no_matches = np.array([-1] * 6, dtype=np.intp) diff --git a/pandas/tests/test_algos.py b/pandas/tests/test_algos.py index ad08440ecd111..28ceaa61c558f 100644 --- a/pandas/tests/test_algos.py +++ b/pandas/tests/test_algos.py @@ -1545,10 +1545,7 @@ def test_lookup_nan(self, writable): xs.setflags(write=writable) m = ht.Float64HashTable() m.map_locations(xs) - expected_dtype = np.int64 if IS64 else np.int32 - tm.assert_numpy_array_equal( - m.lookup(xs), np.arange(len(xs), dtype=expected_dtype) - ) + tm.assert_numpy_array_equal(m.lookup(xs), np.arange(len(xs), dtype=np.intp)) def test_add_signed_zeros(self): # GH 21866 inconsistent hash-function for float64 @@ -1581,10 +1578,7 @@ def test_lookup_overflow(self, writable): xs.setflags(write=writable) m = ht.UInt64HashTable() m.map_locations(xs) - expected_dtype = np.int64 if IS64 else np.int32 - tm.assert_numpy_array_equal( - m.lookup(xs), np.arange(len(xs), dtype=expected_dtype) - ) + tm.assert_numpy_array_equal(m.lookup(xs), np.arange(len(xs), dtype=np.intp)) def test_get_unique(self): s = Series([1, 2, 2 ** 63, 2 ** 63], dtype=np.uint64)