54
54
class TestFactorize :
55
55
def test_factorize_complex (self ):
56
56
# GH#17927
57
- array = [1 , 2 , 2 + 1j ]
58
- msg = "factorize with argument that is not not a Series"
59
- with tm .assert_produces_warning (FutureWarning , match = msg ):
60
- labels , uniques = algos .factorize (array )
57
+ array = np .array ([1 , 2 , 2 + 1j ], dtype = complex )
58
+ labels , uniques = algos .factorize (array )
61
59
62
60
expected_labels = np .array ([0 , 1 , 2 ], dtype = np .intp )
63
61
tm .assert_numpy_array_equal (labels , expected_labels )
64
62
65
- # Should return a complex dtype in the future
66
- expected_uniques = np .array ([(1 + 0j ), (2 + 0j ), (2 + 1j )], dtype = object )
63
+ expected_uniques = np .array ([(1 + 0j ), (2 + 0j ), (2 + 1j )], dtype = complex )
67
64
tm .assert_numpy_array_equal (uniques , expected_uniques )
68
65
69
66
def test_factorize (self , index_or_series_obj , sort ):
@@ -265,9 +262,8 @@ def test_factorizer_object_with_nan(self):
265
262
)
266
263
def test_factorize_tuple_list (self , data , expected_codes , expected_uniques ):
267
264
# GH9454
268
- msg = "factorize with argument that is not not a Series"
269
- with tm .assert_produces_warning (FutureWarning , match = msg ):
270
- codes , uniques = pd .factorize (data )
265
+ data = com .asarray_tuplesafe (data , dtype = object )
266
+ codes , uniques = pd .factorize (data )
271
267
272
268
tm .assert_numpy_array_equal (codes , np .array (expected_codes , dtype = np .intp ))
273
269
@@ -488,12 +484,12 @@ def test_object_factorize_use_na_sentinel_false(
488
484
"data, expected_codes, expected_uniques" ,
489
485
[
490
486
(
491
- [1 , None , 1 , 2 ],
487
+ np . array ( [1 , None , 1 , 2 ], dtype = object ) ,
492
488
np .array ([0 , 1 , 0 , 2 ], dtype = np .dtype ("intp" )),
493
489
np .array ([1 , np .nan , 2 ], dtype = "O" ),
494
490
),
495
491
(
496
- [1 , np .nan , 1 , 2 ],
492
+ np . array ( [1 , np .nan , 1 , 2 ], dtype = np . float64 ) ,
497
493
np .array ([0 , 1 , 0 , 2 ], dtype = np .dtype ("intp" )),
498
494
np .array ([1 , np .nan , 2 ], dtype = np .float64 ),
499
495
),
@@ -502,9 +498,7 @@ def test_object_factorize_use_na_sentinel_false(
502
498
def test_int_factorize_use_na_sentinel_false (
503
499
self , data , expected_codes , expected_uniques
504
500
):
505
- msg = "factorize with argument that is not not a Series"
506
- with tm .assert_produces_warning (FutureWarning , match = msg ):
507
- codes , uniques = algos .factorize (data , use_na_sentinel = False )
501
+ codes , uniques = algos .factorize (data , use_na_sentinel = False )
508
502
509
503
tm .assert_numpy_array_equal (uniques , expected_uniques , strict_nan = True )
510
504
tm .assert_numpy_array_equal (codes , expected_codes , strict_nan = True )
@@ -777,9 +771,8 @@ def test_order_of_appearance(self):
777
771
result = pd .unique (Series ([2 ] + [1 ] * 5 ))
778
772
tm .assert_numpy_array_equal (result , np .array ([2 , 1 ], dtype = "int64" ))
779
773
780
- msg = "unique with argument that is not not a Series, Index,"
781
- with tm .assert_produces_warning (FutureWarning , match = msg ):
782
- result = pd .unique (list ("aabc" ))
774
+ data = np .array (["a" , "a" , "b" , "c" ], dtype = object )
775
+ result = pd .unique (data )
783
776
expected = np .array (["a" , "b" , "c" ], dtype = object )
784
777
tm .assert_numpy_array_equal (result , expected )
785
778
@@ -815,9 +808,8 @@ def test_order_of_appearance_dt64tz(self, unit):
815
808
)
816
809
def test_tuple_with_strings (self , arg , expected ):
817
810
# see GH 17108
818
- msg = "unique with argument that is not not a Series"
819
- with tm .assert_produces_warning (FutureWarning , match = msg ):
820
- result = pd .unique (arg )
811
+ arg = com .asarray_tuplesafe (arg , dtype = object )
812
+ result = pd .unique (arg )
821
813
tm .assert_numpy_array_equal (result , expected )
822
814
823
815
def test_obj_none_preservation (self ):
@@ -904,12 +896,6 @@ def test_invalid(self):
904
896
algos .isin ([1 ], 1 )
905
897
906
898
def test_basic (self ):
907
- msg = "isin with argument that is not not a Series"
908
- with tm .assert_produces_warning (FutureWarning , match = msg ):
909
- result = algos .isin ([1 , 2 ], [1 ])
910
- expected = np .array ([True , False ])
911
- tm .assert_numpy_array_equal (result , expected )
912
-
913
899
result = algos .isin (np .array ([1 , 2 ]), [1 ])
914
900
expected = np .array ([True , False ])
915
901
tm .assert_numpy_array_equal (result , expected )
@@ -926,21 +912,20 @@ def test_basic(self):
926
912
expected = np .array ([True , False ])
927
913
tm .assert_numpy_array_equal (result , expected )
928
914
929
- with tm . assert_produces_warning ( FutureWarning , match = msg ):
930
- result = algos .isin ([ "a" , "b" ] , ["a" ])
915
+ arg = np . array ([ "a" , "b" ], dtype = object )
916
+ result = algos .isin (arg , ["a" ])
931
917
expected = np .array ([True , False ])
932
918
tm .assert_numpy_array_equal (result , expected )
933
919
934
- result = algos .isin (Series ([ "a" , "b" ] ), Series (["a" ]))
920
+ result = algos .isin (Series (arg ), Series (["a" ]))
935
921
expected = np .array ([True , False ])
936
922
tm .assert_numpy_array_equal (result , expected )
937
923
938
- result = algos .isin (Series ([ "a" , "b" ] ), {"a" })
924
+ result = algos .isin (Series (arg ), {"a" })
939
925
expected = np .array ([True , False ])
940
926
tm .assert_numpy_array_equal (result , expected )
941
927
942
- with tm .assert_produces_warning (FutureWarning , match = msg ):
943
- result = algos .isin (["a" , "b" ], [1 ])
928
+ result = algos .isin (arg , [1 ])
944
929
expected = np .array ([False , False ])
945
930
tm .assert_numpy_array_equal (result , expected )
946
931
@@ -1058,12 +1043,10 @@ def test_same_nan_is_in(self):
1058
1043
# at least, isin() should follow python's "np.nan in [nan] == True"
1059
1044
# casting to -> np.float64 -> another float-object somewhere on
1060
1045
# the way could lead jeopardize this behavior
1061
- comps = [np .nan ] # could be casted to float64
1046
+ comps = np . array ( [np .nan ], dtype = object ) # could be casted to float64
1062
1047
values = [np .nan ]
1063
1048
expected = np .array ([True ])
1064
- msg = "isin with argument that is not not a Series"
1065
- with tm .assert_produces_warning (FutureWarning , match = msg ):
1066
- result = algos .isin (comps , values )
1049
+ result = algos .isin (comps , values )
1067
1050
tm .assert_numpy_array_equal (expected , result )
1068
1051
1069
1052
def test_same_nan_is_in_large (self ):
@@ -1098,12 +1081,12 @@ def __hash__(self):
1098
1081
1099
1082
a , b = LikeNan (), LikeNan ()
1100
1083
1101
- msg = "isin with argument that is not not a Series"
1102
- with tm . assert_produces_warning ( FutureWarning , match = msg ):
1103
- # same object -> True
1104
- tm .assert_numpy_array_equal (algos .isin ([ a ] , [a ]), np .array ([True ]))
1105
- # different objects -> False
1106
- tm .assert_numpy_array_equal (algos .isin ([ a ] , [b ]), np .array ([False ]))
1084
+ arg = np . array ([ a ], dtype = object )
1085
+
1086
+ # same object -> True
1087
+ tm .assert_numpy_array_equal (algos .isin (arg , [a ]), np .array ([True ]))
1088
+ # different objects -> False
1089
+ tm .assert_numpy_array_equal (algos .isin (arg , [b ]), np .array ([False ]))
1107
1090
1108
1091
def test_different_nans (self ):
1109
1092
# GH 22160
@@ -1132,12 +1115,11 @@ def test_different_nans(self):
1132
1115
def test_no_cast (self ):
1133
1116
# GH 22160
1134
1117
# ensure 42 is not casted to a string
1135
- comps = ["ss" , 42 ]
1118
+ comps = np . array ( ["ss" , 42 ], dtype = object )
1136
1119
values = ["42" ]
1137
1120
expected = np .array ([False , False ])
1138
- msg = "isin with argument that is not not a Series, Index"
1139
- with tm .assert_produces_warning (FutureWarning , match = msg ):
1140
- result = algos .isin (comps , values )
1121
+
1122
+ result = algos .isin (comps , values )
1141
1123
tm .assert_numpy_array_equal (expected , result )
1142
1124
1143
1125
@pytest .mark .parametrize ("empty" , [[], Series (dtype = object ), np .array ([])])
@@ -1658,27 +1640,32 @@ def test_unique_tuples(self, arr, uniques):
1658
1640
expected = np .empty (len (uniques ), dtype = object )
1659
1641
expected [:] = uniques
1660
1642
1661
- msg = "unique with argument that is not not a Series"
1662
- with tm .assert_produces_warning (FutureWarning , match = msg ):
1663
- result = pd .unique (arr )
1664
- tm .assert_numpy_array_equal (result , expected )
1643
+ msg = "unique requires a Series, Index, ExtensionArray, or np.ndarray, got list"
1644
+ with pytest .raises (TypeError , match = msg ):
1645
+ # GH#52986
1646
+ pd .unique (arr )
1647
+
1648
+ res = pd .unique (com .asarray_tuplesafe (arr , dtype = object ))
1649
+ tm .assert_numpy_array_equal (res , expected )
1665
1650
1666
1651
@pytest .mark .parametrize (
1667
1652
"array,expected" ,
1668
1653
[
1669
1654
(
1670
1655
[1 + 1j , 0 , 1 , 1j , 1 + 2j , 1 + 2j ],
1671
- # Should return a complex dtype in the future
1672
- np .array ([(1 + 1j ), 0j , (1 + 0j ), 1j , (1 + 2j )], dtype = object ),
1656
+ np .array ([(1 + 1j ), 0j , (1 + 0j ), 1j , (1 + 2j )], dtype = complex ),
1673
1657
)
1674
1658
],
1675
1659
)
1676
1660
def test_unique_complex_numbers (self , array , expected ):
1677
1661
# GH 17927
1678
- msg = "unique with argument that is not not a Series"
1679
- with tm .assert_produces_warning (FutureWarning , match = msg ):
1680
- result = pd .unique (array )
1681
- tm .assert_numpy_array_equal (result , expected )
1662
+ msg = "unique requires a Series, Index, ExtensionArray, or np.ndarray, got list"
1663
+ with pytest .raises (TypeError , match = msg ):
1664
+ # GH#52986
1665
+ pd .unique (array )
1666
+
1667
+ res = pd .unique (np .array (array ))
1668
+ tm .assert_numpy_array_equal (res , expected )
1682
1669
1683
1670
1684
1671
class TestHashTable :
0 commit comments