@@ -32,6 +32,46 @@ def test_apply_simple_series(self, data):
32
32
result = pd .Series (data ).apply (id )
33
33
assert isinstance (result , pd .Series )
34
34
35
+ def test_argsort (self , data_for_sorting ):
36
+ result = pd .Series (data_for_sorting ).argsort ()
37
+ expected = pd .Series (np .array ([2 , 0 , 1 ], dtype = np .int64 ))
38
+ self .assert_series_equal (result , expected )
39
+
40
+ def test_argsort_missing (self , data_missing_for_sorting ):
41
+ result = pd .Series (data_missing_for_sorting ).argsort ()
42
+ expected = pd .Series (np .array ([1 , - 1 , 0 ], dtype = np .int64 ))
43
+ self .assert_series_equal (result , expected )
44
+
45
+ @pytest .mark .parametrize ('ascending' , [True , False ])
46
+ def test_sort_values (self , data_for_sorting , ascending ):
47
+ ser = pd .Series (data_for_sorting )
48
+ result = ser .sort_values (ascending = ascending )
49
+ expected = ser .iloc [[2 , 0 , 1 ]]
50
+ if not ascending :
51
+ expected = expected [::- 1 ]
52
+
53
+ self .assert_series_equal (result , expected )
54
+
55
+ @pytest .mark .parametrize ('ascending' , [True , False ])
56
+ def test_sort_values_missing (self , data_missing_for_sorting , ascending ):
57
+ ser = pd .Series (data_missing_for_sorting )
58
+ result = ser .sort_values (ascending = ascending )
59
+ if ascending :
60
+ expected = ser .iloc [[2 , 0 , 1 ]]
61
+ else :
62
+ expected = ser .iloc [[0 , 2 , 1 ]]
63
+ self .assert_series_equal (result , expected )
64
+
65
+ @pytest .mark .parametrize ('ascending' , [True , False ])
66
+ def test_sort_values_frame (self , data_for_sorting , ascending ):
67
+ df = pd .DataFrame ({"A" : [1 , 2 , 1 ],
68
+ "B" : data_for_sorting })
69
+ result = df .sort_values (['A' , 'B' ])
70
+ expected = pd .DataFrame ({"A" : [1 , 1 , 2 ],
71
+ 'B' : data_for_sorting .take ([2 , 0 , 1 ])},
72
+ index = [2 , 0 , 1 ])
73
+ self .assert_frame_equal (result , expected )
74
+
35
75
@pytest .mark .parametrize ('box' , [pd .Series , lambda x : x ])
36
76
@pytest .mark .parametrize ('method' , [lambda x : x .unique (), pd .unique ])
37
77
def test_unique (self , data , box , method ):
0 commit comments