From b3d1cd4bb4e7dc302f0098830a981a6af5bd00b7 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Fri, 2 Sep 2016 19:31:48 -0400 Subject: [PATCH] TST: sparse / dummy array comparisons on windows, xref #14140 --- pandas/sparse/tests/test_list.py | 5 ++++- pandas/tests/test_reshape.py | 2 +- pandas/util/testing.py | 21 +++++++++++++++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/pandas/sparse/tests/test_list.py b/pandas/sparse/tests/test_list.py index 0b933b4f9c6f2..b117685b6e968 100644 --- a/pandas/sparse/tests/test_list.py +++ b/pandas/sparse/tests/test_list.py @@ -60,8 +60,11 @@ def test_append_zero(self): splist.append(arr[5]) splist.append(arr[6:]) + # list always produces int64, but SA constructor + # is platform dtype aware sparr = splist.to_array() - tm.assert_sp_array_equal(sparr, SparseArray(arr, fill_value=0)) + exp = SparseArray(arr, fill_value=0) + tm.assert_sp_array_equal(sparr, exp, check_dtype=False) def test_consolidate(self): with tm.assert_produces_warning(FutureWarning, diff --git a/pandas/tests/test_reshape.py b/pandas/tests/test_reshape.py index 413724d1a6177..80d1f5f76e5a9 100644 --- a/pandas/tests/test_reshape.py +++ b/pandas/tests/test_reshape.py @@ -323,7 +323,7 @@ def test_dataframe_dummies_prefix_str(self): [3, 1, 0, 0, 1]], columns=['C', 'bad_a', 'bad_b', 'bad_b', 'bad_c'], dtype=np.uint8) - expected = expected.astype({"C": np.int}) + expected = expected.astype({"C": np.int64}) assert_frame_equal(result, expected) def test_dataframe_dummies_subset(self): diff --git a/pandas/util/testing.py b/pandas/util/testing.py index d50a6c460ceb5..f5a93d1f17d00 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -1385,11 +1385,22 @@ def assert_panelnd_equal(left, right, # Sparse -def assert_sp_array_equal(left, right): +def assert_sp_array_equal(left, right, check_dtype=True): + """Check that the left and right SparseArray are equal. + + Parameters + ---------- + left : SparseArray + right : SparseArray + check_dtype : bool, default True + Whether to check the data dtype is identical. + """ + assertIsInstance(left, pd.SparseArray, '[SparseArray]') assertIsInstance(right, pd.SparseArray, '[SparseArray]') - assert_numpy_array_equal(left.sp_values, right.sp_values) + assert_numpy_array_equal(left.sp_values, right.sp_values, + check_dtype=check_dtype) # SparseIndex comparison assertIsInstance(left.sp_index, pd._sparse.SparseIndex, '[SparseIndex]') @@ -1400,8 +1411,10 @@ def assert_sp_array_equal(left, right): left.sp_index, right.sp_index) assert_attr_equal('fill_value', left, right) - assert_attr_equal('dtype', left, right) - assert_numpy_array_equal(left.values, right.values) + if check_dtype: + assert_attr_equal('dtype', left, right) + assert_numpy_array_equal(left.values, right.values, + check_dtype=check_dtype) def assert_sp_series_equal(left, right, check_dtype=True, exact_indices=True,