@@ -907,144 +907,6 @@ def test_matmul(self):
907
907
pytest .raises (Exception , a .dot , a .values [:3 ])
908
908
pytest .raises (ValueError , a .dot , b .T )
909
909
910
- def test_value_counts_nunique (self ):
911
-
912
- # basics.rst doc example
913
- series = Series (np .random .randn (500 ))
914
- series [20 :500 ] = np .nan
915
- series [10 :20 ] = 5000
916
- result = series .nunique ()
917
- assert result == 11
918
-
919
- # GH 18051
920
- s = pd .Series (pd .Categorical ([]))
921
- assert s .nunique () == 0
922
- s = pd .Series (pd .Categorical ([np .nan ]))
923
- assert s .nunique () == 0
924
-
925
- def test_unique (self ):
926
-
927
- # 714 also, dtype=float
928
- s = Series ([1.2345 ] * 100 )
929
- s [::2 ] = np .nan
930
- result = s .unique ()
931
- assert len (result ) == 2
932
-
933
- s = Series ([1.2345 ] * 100 , dtype = 'f4' )
934
- s [::2 ] = np .nan
935
- result = s .unique ()
936
- assert len (result ) == 2
937
-
938
- # NAs in object arrays #714
939
- s = Series (['foo' ] * 100 , dtype = 'O' )
940
- s [::2 ] = np .nan
941
- result = s .unique ()
942
- assert len (result ) == 2
943
-
944
- # decision about None
945
- s = Series ([1 , 2 , 3 , None , None , None ], dtype = object )
946
- result = s .unique ()
947
- expected = np .array ([1 , 2 , 3 , None ], dtype = object )
948
- tm .assert_numpy_array_equal (result , expected )
949
-
950
- # GH 18051
951
- s = pd .Series (pd .Categorical ([]))
952
- tm .assert_categorical_equal (s .unique (), pd .Categorical ([]),
953
- check_dtype = False )
954
- s = pd .Series (pd .Categorical ([np .nan ]))
955
- tm .assert_categorical_equal (s .unique (), pd .Categorical ([np .nan ]),
956
- check_dtype = False )
957
-
958
- @pytest .mark .parametrize (
959
- "tc1, tc2" ,
960
- [
961
- (
962
- Series ([1 , 2 , 3 , 3 ], dtype = np .dtype ('int_' )),
963
- Series ([1 , 2 , 3 , 5 , 3 , 2 , 4 ], dtype = np .dtype ('int_' ))
964
- ),
965
- (
966
- Series ([1 , 2 , 3 , 3 ], dtype = np .dtype ('uint' )),
967
- Series ([1 , 2 , 3 , 5 , 3 , 2 , 4 ], dtype = np .dtype ('uint' ))
968
- ),
969
- (
970
- Series ([1 , 2 , 3 , 3 ], dtype = np .dtype ('float_' )),
971
- Series ([1 , 2 , 3 , 5 , 3 , 2 , 4 ], dtype = np .dtype ('float_' ))
972
- ),
973
- (
974
- Series ([1 , 2 , 3 , 3 ], dtype = np .dtype ('unicode_' )),
975
- Series ([1 , 2 , 3 , 5 , 3 , 2 , 4 ], dtype = np .dtype ('unicode_' ))
976
- )
977
- ]
978
- )
979
- def test_drop_duplicates_non_bool (self , tc1 , tc2 ):
980
- # Test case 1
981
- expected = Series ([False , False , False , True ])
982
- assert_series_equal (tc1 .duplicated (), expected )
983
- assert_series_equal (tc1 .drop_duplicates (), tc1 [~ expected ])
984
- sc = tc1 .copy ()
985
- sc .drop_duplicates (inplace = True )
986
- assert_series_equal (sc , tc1 [~ expected ])
987
-
988
- expected = Series ([False , False , True , False ])
989
- assert_series_equal (tc1 .duplicated (keep = 'last' ), expected )
990
- assert_series_equal (tc1 .drop_duplicates (keep = 'last' ), tc1 [~ expected ])
991
- sc = tc1 .copy ()
992
- sc .drop_duplicates (keep = 'last' , inplace = True )
993
- assert_series_equal (sc , tc1 [~ expected ])
994
-
995
- expected = Series ([False , False , True , True ])
996
- assert_series_equal (tc1 .duplicated (keep = False ), expected )
997
- assert_series_equal (tc1 .drop_duplicates (keep = False ), tc1 [~ expected ])
998
- sc = tc1 .copy ()
999
- sc .drop_duplicates (keep = False , inplace = True )
1000
- assert_series_equal (sc , tc1 [~ expected ])
1001
-
1002
- # Test case 2
1003
- expected = Series ([False , False , False , False , True , True , False ])
1004
- assert_series_equal (tc2 .duplicated (), expected )
1005
- assert_series_equal (tc2 .drop_duplicates (), tc2 [~ expected ])
1006
- sc = tc2 .copy ()
1007
- sc .drop_duplicates (inplace = True )
1008
- assert_series_equal (sc , tc2 [~ expected ])
1009
-
1010
- expected = Series ([False , True , True , False , False , False , False ])
1011
- assert_series_equal (tc2 .duplicated (keep = 'last' ), expected )
1012
- assert_series_equal (tc2 .drop_duplicates (keep = 'last' ), tc2 [~ expected ])
1013
- sc = tc2 .copy ()
1014
- sc .drop_duplicates (keep = 'last' , inplace = True )
1015
- assert_series_equal (sc , tc2 [~ expected ])
1016
-
1017
- expected = Series ([False , True , True , False , True , True , False ])
1018
- assert_series_equal (tc2 .duplicated (keep = False ), expected )
1019
- assert_series_equal (tc2 .drop_duplicates (keep = False ), tc2 [~ expected ])
1020
- sc = tc2 .copy ()
1021
- sc .drop_duplicates (keep = False , inplace = True )
1022
- assert_series_equal (sc , tc2 [~ expected ])
1023
-
1024
- def test_drop_duplicates_bool (self ):
1025
- tc = Series ([True , False , True , False ])
1026
-
1027
- expected = Series ([False , False , True , True ])
1028
- assert_series_equal (tc .duplicated (), expected )
1029
- assert_series_equal (tc .drop_duplicates (), tc [~ expected ])
1030
- sc = tc .copy ()
1031
- sc .drop_duplicates (inplace = True )
1032
- assert_series_equal (sc , tc [~ expected ])
1033
-
1034
- expected = Series ([True , True , False , False ])
1035
- assert_series_equal (tc .duplicated (keep = 'last' ), expected )
1036
- assert_series_equal (tc .drop_duplicates (keep = 'last' ), tc [~ expected ])
1037
- sc = tc .copy ()
1038
- sc .drop_duplicates (keep = 'last' , inplace = True )
1039
- assert_series_equal (sc , tc [~ expected ])
1040
-
1041
- expected = Series ([True , True , True , True ])
1042
- assert_series_equal (tc .duplicated (keep = False ), expected )
1043
- assert_series_equal (tc .drop_duplicates (keep = False ), tc [~ expected ])
1044
- sc = tc .copy ()
1045
- sc .drop_duplicates (keep = False , inplace = True )
1046
- assert_series_equal (sc , tc [~ expected ])
1047
-
1048
910
def test_clip (self ):
1049
911
val = self .ts .median ()
1050
912
@@ -1416,7 +1278,8 @@ def test_ptp(self):
1416
1278
N = 1000
1417
1279
arr = np .random .randn (N )
1418
1280
ser = Series (arr )
1419
- assert np .ptp (ser ) == np .ptp (arr )
1281
+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
1282
+ assert np .ptp (ser ) == np .ptp (arr )
1420
1283
1421
1284
# GH11163
1422
1285
s = Series ([3 , 5 , np .nan , - 3 , 10 ])
@@ -1457,10 +1320,6 @@ def test_empty_timeseries_redections_return_nat(self):
1457
1320
assert Series ([], dtype = dtype ).min () is pd .NaT
1458
1321
assert Series ([], dtype = dtype ).max () is pd .NaT
1459
1322
1460
- def test_unique_data_ownership (self ):
1461
- # it works! #1807
1462
- Series (Series (["a" , "c" , "b" ]).unique ()).sort_values ()
1463
-
1464
1323
def test_repeat (self ):
1465
1324
s = Series (np .random .randn (3 ), index = ['a' , 'b' , 'c' ])
1466
1325
@@ -1537,29 +1396,6 @@ def test_searchsorted_sorter(self):
1537
1396
e = np .array ([0 , 2 ], dtype = np .intp )
1538
1397
tm .assert_numpy_array_equal (r , e )
1539
1398
1540
- def test_is_unique (self ):
1541
- # GH11946
1542
- s = Series (np .random .randint (0 , 10 , size = 1000 ))
1543
- assert not s .is_unique
1544
- s = Series (np .arange (1000 ))
1545
- assert s .is_unique
1546
-
1547
- def test_is_unique_class_ne (self , capsys ):
1548
- # GH 20661
1549
- class Foo (object ):
1550
- def __init__ (self , val ):
1551
- self ._value = val
1552
-
1553
- def __ne__ (self , other ):
1554
- raise Exception ("NEQ not supported" )
1555
-
1556
- li = [Foo (i ) for i in range (5 )]
1557
- s = pd .Series (li , index = [i for i in range (5 )])
1558
- _ , err = capsys .readouterr ()
1559
- s .is_unique
1560
- _ , err = capsys .readouterr ()
1561
- assert len (err ) == 0
1562
-
1563
1399
def test_is_monotonic (self ):
1564
1400
1565
1401
s = Series (np .random .randint (0 , 10 , size = 1000 ))
0 commit comments