-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
"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"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, @jreback - now using |
||
(["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", | ||
[ | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.