Skip to content

TST: add test for .unique() dtype preserving #29515

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

Merged
merged 5 commits into from
Nov 14, 2019
Merged
Changes from 3 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
19 changes: 19 additions & 0 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,25 @@ def test_on_index_object(self):

tm.assert_almost_equal(result, expected)

@pytest.mark.parametrize(
"data, uniques, dtype_list",
[
([1, 2, 2], [1, 2], np.sctypes["int"]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would rather not use numpy references here and instead use our fixtures or definitions in pandas/conftest.py they are much more comprehensive and include pandas types

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback, @jreback - now using any_numpy_dtype to extract the dtypes.

([1, 2, 2], [1, 2], np.sctypes["uint"]),
([1, 2, 2], [1.0, 2.0], np.sctypes["float"]),
([1, 2, 2], [1.0, 2.0], np.sctypes["complex"]),
([True, True, False], [True, False], np.sctypes["others"]), # bool, object
],
)
def test_dtype_preservation(self, data, uniques, dtype_list):
# GH 15442
for dtype in dtype_list:
if dtype not in [bytes, str, np.void]:
result = Series(data, dtype=dtype).unique()
expected = np.array(uniques, dtype=dtype)

tm.assert_numpy_array_equal(result, expected)

def test_datetime64_dtype_array_returned(self):
# GH 9431
expected = np_array_datetime64_compat(
Expand Down