Skip to content

Commit 777e801

Browse files
committed
add test for .unique() preserving dtype
1 parent 0de9955 commit 777e801

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/series/test_dtypes.py

+27
Original file line numberDiff line numberDiff line change
@@ -518,3 +518,30 @@ def test_values_compatibility(self, data):
518518
result = pd.Series(data).values
519519
expected = np.array(data.astype(object))
520520
tm.assert_numpy_array_equal(result, expected)
521+
522+
@pytest.mark.parametrize(
523+
"data, uniques, dtype",
524+
[
525+
([1, 2, 2], [1, 2], "int8"),
526+
([1, 2, 2], [1, 2], "int16"),
527+
([1, 2, 2], [1, 2], "int32"),
528+
([1, 2, 2], [1, 2], "int64"),
529+
([1, 2, 2], [1, 2], "uint8"),
530+
([1, 2, 2], [1, 2], "uint16"),
531+
([1, 2, 2], [1, 2], "uint32"),
532+
([1, 2, 2], [1, 2], "uint64"),
533+
([1, 2, 2], [1.0, 2.0], "float16"),
534+
([1, 2, 2], [1.0, 2.0], "float32"),
535+
([1, 2, 2], [1.0, 2.0], "float64"),
536+
([1, 2, 2], [1.0, 2.0], "complex64"),
537+
([1, 2, 2], [1.0, 2.0], "complex128"),
538+
([True, True, False], [True, False], "bool"),
539+
(["A", "A", "B"], ["A", "B"], "object"),
540+
],
541+
)
542+
def test_unique_preserve_dtype(self, data, uniques, dtype):
543+
# GH 15442
544+
result = Series(data, dtype=dtype).unique()
545+
expected = np.array(uniques, dtype=dtype)
546+
547+
tm.assert_numpy_array_equal(result, expected)

0 commit comments

Comments
 (0)