We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bcc60a4 commit 452c7fbCopy full SHA for 452c7fb
ci/code_checks.sh
@@ -73,6 +73,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
73
-i "pandas.Period.freq GL08" \
74
-i "pandas.Period.ordinal GL08" \
75
-i "pandas.errors.IncompatibleFrequency SA01,SS06,EX01" \
76
+ -i "pandas.api.extensions.ExtensionArray.value_counts EX01,RT03,SA01" \
77
-i "pandas.core.groupby.DataFrameGroupBy.plot PR02" \
78
-i "pandas.core.groupby.SeriesGroupBy.plot PR02" \
79
-i "pandas.core.resample.Resampler.quantile PR01,PR07" \
pandas/core/arrays/base.py
@@ -99,7 +99,10 @@
99
npt,
100
)
101
102
- from pandas import Index
+ from pandas import (
103
+ Index,
104
+ Series,
105
+ )
106
107
_extension_array_shared_docs: dict[str, str] = {}
108
@@ -1673,6 +1676,25 @@ def repeat(self, repeats: int | Sequence[int], axis: AxisInt | None = None) -> S
1673
1676
ind = np.arange(len(self)).repeat(repeats)
1674
1677
return self.take(ind)
1675
1678
1679
+ def value_counts(self, dropna: bool = True) -> Series:
1680
+ """
1681
+ Return a Series containing counts of unique values.
1682
+
1683
+ Parameters
1684
+ ----------
1685
+ dropna : bool, default True
1686
+ Don't include counts of NA values.
1687
1688
+ Returns
1689
+ -------
1690
+ Series
1691
1692
+ from pandas.core.algorithms import value_counts_internal as value_counts
1693
1694
+ result = value_counts(self.to_numpy(copy=False), sort=False, dropna=dropna)
1695
+ result.index = result.index.astype(self.dtype)
1696
+ return result
1697
1698
# ------------------------------------------------------------------------
1699
# Indexing methods
1700
pandas/core/arrays/interval.py
@@ -75,7 +75,6 @@
isin,
take,
unique,
- value_counts_internal as value_counts,
80
from pandas.core.arrays import ArrowExtensionArray
81
from pandas.core.arrays.base import (
@@ -105,7 +104,6 @@
from pandas import (
Index,
- Series,
109
110
111
@@ -1197,28 +1195,6 @@ def _validate_setitem_value(self, value):
1197
1195
1198
1196
return value_left, value_right
1199
1200
- def value_counts(self, dropna: bool = True) -> Series:
1201
- """
1202
- Returns a Series containing counts of each interval.
1203
-
1204
- Parameters
1205
- ----------
1206
- dropna : bool, default True
1207
- Don't include counts of NaN.
1208
1209
- Returns
1210
- -------
1211
- counts : Series
1212
1213
- See Also
1214
- --------
1215
- Series.value_counts
1216
1217
- # TODO: implement this is a non-naive way!
1218
- result = value_counts(np.asarray(self), dropna=dropna)
1219
- result.index = result.index.astype(self.dtype)
1220
- return result
1221
1222
# ---------------------------------------------------------------------
1223
# Rendering Methods
1224
pandas/core/arrays/string_.py
@@ -1037,10 +1037,7 @@ def sum(
1037
return self._wrap_reduction_result(axis, result)
1038
1039
def value_counts(self, dropna: bool = True) -> Series:
1040
- from pandas.core.algorithms import value_counts_internal as value_counts
1041
1042
- result = value_counts(self._ndarray, sort=False, dropna=dropna)
1043
+ result = super().value_counts(dropna=dropna)
1044
1045
if self.dtype.na_value is libmissing.NA:
1046
result = result.astype("Int64")
pandas/tests/extension/decimal/array.py
@@ -25,7 +25,6 @@
25
is_scalar,
26
27
from pandas.core import arraylike
28
-from pandas.core.algorithms import value_counts_internal as value_counts
29
from pandas.core.arraylike import OpsMixin
30
from pandas.core.arrays import (
31
ExtensionArray,
@@ -291,9 +290,6 @@ def convert_values(param):
291
290
292
return np.asarray(res, dtype=bool)
293
294
- def value_counts(self, dropna: bool = True):
295
- return value_counts(self.to_numpy(), dropna=dropna)
296
297
# We override fillna here to simulate a 3rd party EA that has done so. This
298
# lets us test a 3rd-party EA that has not yet updated to include a "copy"
299
# keyword in its fillna method.
pandas/tests/extension/decimal/test_decimal.py
@@ -171,26 +171,6 @@ def test_fillna_limit_series(self, data_missing):
171
):
172
super().test_fillna_limit_series(data_missing)
173
174
- @pytest.mark.parametrize("dropna", [True, False])
175
- def test_value_counts(self, all_data, dropna):
176
- all_data = all_data[:10]
177
- if dropna:
178
- other = np.array(all_data[~all_data.isna()])
179
- else:
180
- other = all_data
181
182
- vcs = pd.Series(all_data).value_counts(dropna=dropna)
183
- vcs_ex = pd.Series(other).value_counts(dropna=dropna)
184
185
- with decimal.localcontext() as ctx:
186
- # avoid raising when comparing Decimal("NAN") < Decimal(2)
187
- ctx.traps[decimal.InvalidOperation] = False
188
189
- result = vcs.sort_index()
190
- expected = vcs_ex.sort_index()
191
192
- tm.assert_series_equal(result, expected)
193
194
def test_series_repr(self, data):
195
# Overriding this base test to explicitly test that
196
# the custom _formatter is used
pandas/tests/extension/json/test_json.py
@@ -189,14 +189,12 @@ def test_ffill_limit_area(
data_missing, limit_area, input_ilocs, expected_ilocs
- @unhashable
+ def test_value_counts(self, all_data, dropna, request):
+ if len(all_data) == 100 or dropna:
+ mark = pytest.mark.xfail(reason="unhashable")
+ request.applymarker(mark)
super().test_value_counts(all_data, dropna)
197
- def test_value_counts_with_normalize(self, data):
198
- super().test_value_counts_with_normalize(data)
199
200
@unhashable
201
def test_sort_values_frame(self):
202
# TODO (EA.factorize): see if _values_for_factorize allows this.
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments