Skip to content

Commit c6c4751

Browse files
committed
Expand test
1 parent b025232 commit c6c4751

File tree

5 files changed

+14
-21
lines changed

5 files changed

+14
-21
lines changed

pandas/core/algorithms.py

+2
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,8 @@ def value_counts(
727727
if not isinstance(counts, np.ndarray):
728728
counts = counts.to_numpy()
729729
result = result / float(counts.sum())
730+
else:
731+
result = result.astype("Int64")
730732

731733
return result
732734

pandas/tests/arrays/string_/test_string.py

-10
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,3 @@ def test_value_counts_na():
277277
result = arr.value_counts(dropna=True)
278278
expected = pd.Series([2, 1], index=["a", "b"], dtype="Int64")
279279
tm.assert_series_equal(result, expected)
280-
281-
282-
def test_normalize_value_counts():
283-
result = (
284-
pd.Series(list("abcd"), dtype="string")
285-
.value_counts(normalize=True)
286-
.sort_index()
287-
)
288-
expected = pd.Series([0.25, 0.25, 0.25, 0.25], index=["a", "b", "c", "d"])
289-
tm.assert_series_equal(expected, result)

pandas/tests/extension/base/methods.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
import numpy as np
44
import pytest
55

6-
from pandas.core.dtypes.common import is_bool_dtype
7-
86
import pandas as pd
97
import pandas._testing as tm
8+
from pandas.core.dtypes.common import is_bool_dtype
109
from pandas.core.sorting import nargsort
11-
1210
from .base import BaseExtensionTests
1311

1412

@@ -17,7 +15,7 @@ class BaseMethodsTests(BaseExtensionTests):
1715

1816
@pytest.mark.parametrize("dropna", [True, False])
1917
def test_value_counts(self, all_data, dropna):
20-
all_data = all_data[:10]
18+
all_data = all_data[:5]
2119
if dropna:
2220
other = np.array(all_data[~all_data.isna()])
2321
else:
@@ -28,6 +26,15 @@ def test_value_counts(self, all_data, dropna):
2826

2927
self.assert_series_equal(result, expected)
3028

29+
result = (
30+
pd.Series(all_data, dtype=all_data.dtype)
31+
.value_counts(dropna=dropna, normalize=True)
32+
.sort_index()
33+
)
34+
35+
expected = pd.Series([1 / len(other)] * len(other), index=result.index)
36+
tm.assert_series_equal(expected, result)
37+
3138
def test_count(self, data_missing):
3239
df = pd.DataFrame({"A": data_missing})
3340
result = df.count(axis="columns")

pandas/tests/extension/test_datetime.py

-4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ class TestGetitem(BaseDatetimeTests, base.BaseGetitemTests):
9090

9191

9292
class TestMethods(BaseDatetimeTests, base.BaseMethodsTests):
93-
@pytest.mark.skip(reason="Incorrect expected")
94-
def test_value_counts(self, all_data, dropna):
95-
pass
96-
9793
def test_combine_add(self, data_repeated):
9894
# Timestamp.__add__(Timestamp) not defined
9995
pass

pandas/tests/extension/test_string.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ class TestNoReduce(base.BaseNoReduceTests):
8181

8282

8383
class TestMethods(base.BaseMethodsTests):
84-
@pytest.mark.skip(reason="returns nullable")
85-
def test_value_counts(self, all_data, dropna):
86-
return super().test_value_counts(all_data, dropna)
84+
pass
8785

8886

8987
class TestCasting(base.BaseCastingTests):

0 commit comments

Comments
 (0)