Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: sparse / dummy array comparisons on windows, xref #14140 #14141

Merged
merged 1 commit into from
Sep 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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