Skip to content

Commit

Permalink
TST: sparse / dummy array comparisons on windows, xref pandas-dev#14140
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback committed Sep 2, 2016
1 parent d26363b commit b3d1cd4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion pandas/sparse/tests/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
21 changes: 17 additions & 4 deletions pandas/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]')
Expand All @@ -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,
Expand Down

0 comments on commit b3d1cd4

Please sign in to comment.