@@ -67,72 +67,124 @@ def test_drop_duplicates_no_duplicates(any_numpy_dtype, keep, values):
67
67
68
68
69
69
class TestSeriesDropDuplicates :
70
- @pytest .mark .parametrize (
71
- "dtype" ,
72
- ["int_" , "uint" , "float_" , "unicode_" , "timedelta64[h]" , "datetime64[D]" ],
70
+ @pytest .fixture (
71
+ params = ["int_" , "uint" , "float_" , "unicode_" , "timedelta64[h]" , "datetime64[D]" ]
73
72
)
74
- def test_drop_duplicates_categorical_non_bool (self , dtype , ordered ):
75
- cat_array = np . array ([ 1 , 2 , 3 , 4 , 5 ], dtype = np . dtype ( dtype ))
73
+ def dtype (self , request ):
74
+ return request . param
76
75
76
+ @pytest .fixture
77
+ def cat_series1 (self , dtype , ordered ):
77
78
# Test case 1
79
+ cat_array = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .dtype (dtype ))
80
+
78
81
input1 = np .array ([1 , 2 , 3 , 3 ], dtype = np .dtype (dtype ))
79
- tc1 = Series (Categorical (input1 , categories = cat_array , ordered = ordered ))
80
- if dtype == "datetime64[D]" :
81
- # pre-empty flaky xfail, tc1 values are seemingly-random
82
- if not (np .array (tc1 ) == input1 ).all ():
83
- pytest .xfail (reason = "GH#7996" )
82
+ cat = Categorical (input1 , categories = cat_array , ordered = ordered )
83
+ tc1 = Series (cat )
84
+ return tc1
85
+
86
+ def test_drop_duplicates_categorical_non_bool (self , cat_series1 ):
87
+ tc1 = cat_series1
84
88
85
89
expected = Series ([False , False , False , True ])
86
- tm .assert_series_equal (tc1 .duplicated (), expected )
87
- tm .assert_series_equal (tc1 .drop_duplicates (), tc1 [~ expected ])
90
+
91
+ result = tc1 .duplicated ()
92
+ tm .assert_series_equal (result , expected )
93
+
94
+ result = tc1 .drop_duplicates ()
95
+ tm .assert_series_equal (result , tc1 [~ expected ])
96
+
88
97
sc = tc1 .copy ()
89
98
return_value = sc .drop_duplicates (inplace = True )
90
99
assert return_value is None
91
100
tm .assert_series_equal (sc , tc1 [~ expected ])
92
101
102
+ def test_drop_duplicates_categorical_non_bool_keeplast (self , cat_series1 ):
103
+ tc1 = cat_series1
104
+
93
105
expected = Series ([False , False , True , False ])
94
- tm .assert_series_equal (tc1 .duplicated (keep = "last" ), expected )
95
- tm .assert_series_equal (tc1 .drop_duplicates (keep = "last" ), tc1 [~ expected ])
106
+
107
+ result = tc1 .duplicated (keep = "last" )
108
+ tm .assert_series_equal (result , expected )
109
+
110
+ result = tc1 .drop_duplicates (keep = "last" )
111
+ tm .assert_series_equal (result , tc1 [~ expected ])
112
+
96
113
sc = tc1 .copy ()
97
114
return_value = sc .drop_duplicates (keep = "last" , inplace = True )
98
115
assert return_value is None
99
116
tm .assert_series_equal (sc , tc1 [~ expected ])
100
117
118
+ def test_drop_duplicates_categorical_non_bool_keepfalse (self , cat_series1 ):
119
+ tc1 = cat_series1
120
+
101
121
expected = Series ([False , False , True , True ])
102
- tm .assert_series_equal (tc1 .duplicated (keep = False ), expected )
103
- tm .assert_series_equal (tc1 .drop_duplicates (keep = False ), tc1 [~ expected ])
122
+
123
+ result = tc1 .duplicated (keep = False )
124
+ tm .assert_series_equal (result , expected )
125
+
126
+ result = tc1 .drop_duplicates (keep = False )
127
+ tm .assert_series_equal (result , tc1 [~ expected ])
128
+
104
129
sc = tc1 .copy ()
105
130
return_value = sc .drop_duplicates (keep = False , inplace = True )
106
131
assert return_value is None
107
132
tm .assert_series_equal (sc , tc1 [~ expected ])
108
133
109
- # Test case 2
134
+ @pytest .fixture
135
+ def cat_series2 (self , dtype , ordered ):
136
+ # Test case 2; TODO: better name
137
+ cat_array = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = np .dtype (dtype ))
138
+
110
139
input2 = np .array ([1 , 2 , 3 , 5 , 3 , 2 , 4 ], dtype = np .dtype (dtype ))
111
- tc2 = Series (Categorical (input2 , categories = cat_array , ordered = ordered ))
112
- if dtype == "datetime64[D]" :
113
- # pre-empty flaky xfail, tc2 values are seemingly-random
114
- if not (np .array (tc2 ) == input2 ).all ():
115
- pytest .xfail (reason = "GH#7996" )
140
+ cat = Categorical (input2 , categories = cat_array , ordered = ordered )
141
+ tc2 = Series (cat )
142
+ return tc2
143
+
144
+ def test_drop_duplicates_categorical_non_bool2 (self , cat_series2 ):
145
+ # Test case 2; TODO: better name
146
+ tc2 = cat_series2
116
147
117
148
expected = Series ([False , False , False , False , True , True , False ])
118
- tm .assert_series_equal (tc2 .duplicated (), expected )
119
- tm .assert_series_equal (tc2 .drop_duplicates (), tc2 [~ expected ])
149
+
150
+ result = tc2 .duplicated ()
151
+ tm .assert_series_equal (result , expected )
152
+
153
+ result = tc2 .drop_duplicates ()
154
+ tm .assert_series_equal (result , tc2 [~ expected ])
155
+
120
156
sc = tc2 .copy ()
121
157
return_value = sc .drop_duplicates (inplace = True )
122
158
assert return_value is None
123
159
tm .assert_series_equal (sc , tc2 [~ expected ])
124
160
161
+ def test_drop_duplicates_categorical_non_bool2_keeplast (self , cat_series2 ):
162
+ tc2 = cat_series2
163
+
125
164
expected = Series ([False , True , True , False , False , False , False ])
126
- tm .assert_series_equal (tc2 .duplicated (keep = "last" ), expected )
127
- tm .assert_series_equal (tc2 .drop_duplicates (keep = "last" ), tc2 [~ expected ])
165
+
166
+ result = tc2 .duplicated (keep = "last" )
167
+ tm .assert_series_equal (result , expected )
168
+
169
+ result = tc2 .drop_duplicates (keep = "last" )
170
+ tm .assert_series_equal (result , tc2 [~ expected ])
171
+
128
172
sc = tc2 .copy ()
129
173
return_value = sc .drop_duplicates (keep = "last" , inplace = True )
130
174
assert return_value is None
131
175
tm .assert_series_equal (sc , tc2 [~ expected ])
132
176
177
+ def test_drop_duplicates_categorical_non_bool2_keepfalse (self , cat_series2 ):
178
+ tc2 = cat_series2
179
+
133
180
expected = Series ([False , True , True , False , True , True , False ])
134
- tm .assert_series_equal (tc2 .duplicated (keep = False ), expected )
135
- tm .assert_series_equal (tc2 .drop_duplicates (keep = False ), tc2 [~ expected ])
181
+
182
+ result = tc2 .duplicated (keep = False )
183
+ tm .assert_series_equal (result , expected )
184
+
185
+ result = tc2 .drop_duplicates (keep = False )
186
+ tm .assert_series_equal (result , tc2 [~ expected ])
187
+
136
188
sc = tc2 .copy ()
137
189
return_value = sc .drop_duplicates (keep = False , inplace = True )
138
190
assert return_value is None
0 commit comments