|
18 | 18 | import numpy as np
|
19 | 19 | import pytest
|
20 | 20 |
|
21 |
| -from pandas.compat import pa_version_under7p0 |
22 | 21 | from pandas.errors import PerformanceWarning
|
23 | 22 |
|
24 | 23 | import pandas as pd
|
@@ -196,70 +195,20 @@ def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna):
|
196 | 195 |
|
197 | 196 |
|
198 | 197 | class TestMethods(base.BaseMethodsTests):
|
199 |
| - def test_argsort(self, data_for_sorting): |
200 |
| - with tm.maybe_produces_warning( |
201 |
| - PerformanceWarning, |
202 |
| - pa_version_under7p0 |
203 |
| - and getattr(data_for_sorting.dtype, "storage", "") == "pyarrow", |
204 |
| - check_stacklevel=False, |
205 |
| - ): |
206 |
| - super().test_argsort(data_for_sorting) |
| 198 | + def test_value_counts_with_normalize(self, data): |
| 199 | + data = data[:10].unique() |
| 200 | + values = np.array(data[~data.isna()]) |
| 201 | + ser = pd.Series(data, dtype=data.dtype) |
207 | 202 |
|
208 |
| - def test_argsort_missing(self, data_missing_for_sorting): |
209 |
| - with tm.maybe_produces_warning( |
210 |
| - PerformanceWarning, |
211 |
| - pa_version_under7p0 |
212 |
| - and getattr(data_missing_for_sorting.dtype, "storage", "") == "pyarrow", |
213 |
| - check_stacklevel=False, |
214 |
| - ): |
215 |
| - super().test_argsort_missing(data_missing_for_sorting) |
216 |
| - |
217 |
| - def test_argmin_argmax( |
218 |
| - self, data_for_sorting, data_missing_for_sorting, na_value, request |
219 |
| - ): |
220 |
| - super().test_argmin_argmax(data_for_sorting, data_missing_for_sorting, na_value) |
221 |
| - |
222 |
| - @pytest.mark.parametrize( |
223 |
| - "op_name, skipna, expected", |
224 |
| - [ |
225 |
| - ("idxmax", True, 0), |
226 |
| - ("idxmin", True, 2), |
227 |
| - ("argmax", True, 0), |
228 |
| - ("argmin", True, 2), |
229 |
| - ("idxmax", False, np.nan), |
230 |
| - ("idxmin", False, np.nan), |
231 |
| - ("argmax", False, -1), |
232 |
| - ("argmin", False, -1), |
233 |
| - ], |
234 |
| - ) |
235 |
| - def test_argreduce_series( |
236 |
| - self, data_missing_for_sorting, op_name, skipna, expected, request |
237 |
| - ): |
238 |
| - super().test_argreduce_series( |
239 |
| - data_missing_for_sorting, op_name, skipna, expected |
240 |
| - ) |
| 203 | + result = ser.value_counts(normalize=True).sort_index() |
241 | 204 |
|
242 |
| - @pytest.mark.parametrize("dropna", [True, False]) |
243 |
| - def test_value_counts(self, all_data, dropna, request): |
244 |
| - all_data = all_data[:10] |
245 |
| - if dropna: |
246 |
| - other = all_data[~all_data.isna()] |
| 205 | + expected = pd.Series( |
| 206 | + [1 / len(values)] * len(values), index=result.index, name="proportion" |
| 207 | + ) |
| 208 | + if getattr(data.dtype, "storage", "") == "pyarrow": |
| 209 | + expected = expected.astype("double[pyarrow]") |
247 | 210 | else:
|
248 |
| - other = all_data |
249 |
| - with tm.maybe_produces_warning( |
250 |
| - PerformanceWarning, |
251 |
| - pa_version_under7p0 |
252 |
| - and getattr(all_data.dtype, "storage", "") == "pyarrow" |
253 |
| - and not (dropna and "data_missing" in request.node.nodeid), |
254 |
| - ): |
255 |
| - result = pd.Series(all_data).value_counts(dropna=dropna).sort_index() |
256 |
| - with tm.maybe_produces_warning( |
257 |
| - PerformanceWarning, |
258 |
| - pa_version_under7p0 |
259 |
| - and getattr(other.dtype, "storage", "") == "pyarrow" |
260 |
| - and not (dropna and "data_missing" in request.node.nodeid), |
261 |
| - ): |
262 |
| - expected = pd.Series(other).value_counts(dropna=dropna).sort_index() |
| 211 | + expected = expected.astype("Float64") |
263 | 212 |
|
264 | 213 | self.assert_series_equal(result, expected)
|
265 | 214 |
|
|
0 commit comments