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 2 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
27 changes: 27 additions & 0 deletions pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,33 @@ def test_is_homogeneous_type(self):
assert Series([1, 2])._is_homogeneous_type
assert Series(pd.Categorical([1, 2]))._is_homogeneous_type

@pytest.mark.parametrize(
Copy link
Contributor

Choose a reason for hiding this comment

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

this should go in pandas/tests/test_algos.py.

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, @jreback - moved the test there.

"data, uniques, dtype",
[
([1, 2, 2], [1, 2], "int8"),
([1, 2, 2], [1, 2], "int16"),
([1, 2, 2], [1, 2], "int32"),
([1, 2, 2], [1, 2], "int64"),
([1, 2, 2], [1, 2], "uint8"),
([1, 2, 2], [1, 2], "uint16"),
([1, 2, 2], [1, 2], "uint32"),
([1, 2, 2], [1, 2], "uint64"),
([1, 2, 2], [1.0, 2.0], "float16"),
([1, 2, 2], [1.0, 2.0], "float32"),
([1, 2, 2], [1.0, 2.0], "float64"),
([1, 2, 2], [1.0, 2.0], "complex64"),
([1, 2, 2], [1.0, 2.0], "complex128"),
([True, True, False], [True, False], "bool"),
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 really try to use the existing fixtures for this, e.g. any_numpy_dtype (and just cast the input in numpy before construction), skipping those which don't make sense.

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, @jreback - now using np.sctypes to extract all dtypes and skipping [bytes, str, np.void].

(["A", "A", "B"], ["A", "B"], "object"),
],
)
def test_unique_preserve_dtype(self, data, uniques, dtype):
# GH 15442
result = Series(data, dtype=dtype).unique()
expected = np.array(uniques, dtype=dtype)

tm.assert_numpy_array_equal(result, expected)

@pytest.mark.parametrize(
"data",
[
Expand Down