@@ -518,3 +518,30 @@ def test_values_compatibility(self, data):
518
518
result = pd .Series (data ).values
519
519
expected = np .array (data .astype (object ))
520
520
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