Skip to content

Commit

Permalink
fix groupby value_counts
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 committed Jan 11, 2023
1 parent eb0ecbe commit 6655dfe
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pandas/tests/groupby/test_value_counts.py
Expand Up @@ -860,7 +860,7 @@ def test_mixed_groupings(normalize, expected_label, expected_values):
result = gp.value_counts(sort=True, normalize=normalize)
expected = DataFrame(
{
"level_0": [4, 4, 5],
"level_0": np.array([4, 4, 5], dtype=np.int_),
"A": [1, 1, 2],
"level_2": [8, 8, 7],
"B": [1, 3, 2],
Expand All @@ -883,7 +883,8 @@ def test_column_label_duplicates(test, columns, expected_names, as_index):
# Test for duplicate input column labels and generated duplicate labels
df = DataFrame([[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]], columns=columns)
expected_data = [(1, 0, 7, 3, 5, 9), (2, 1, 8, 4, 6, 10)]
result = df.groupby(["a", [0, 1], "d"], as_index=as_index).value_counts()
keys = ["a", np.array([0, 1], dtype=np.int64), "d"]
result = df.groupby(keys, as_index=as_index).value_counts()
if as_index:
expected = Series(
data=(1, 1),
Expand Down Expand Up @@ -922,7 +923,7 @@ def test_result_label_duplicates(normalize, expected_label):
def test_ambiguous_grouping():
# Test that groupby is not confused by groupings length equal to row count
df = DataFrame({"a": [1, 1]})
gb = df.groupby([1, 1])
gb = df.groupby(np.array([1, 1], dtype=np.int64))
result = gb.value_counts()
expected = Series([2], index=MultiIndex.from_tuples([[1, 1]], names=[None, "a"]))
tm.assert_series_equal(result, expected)
Expand Down

0 comments on commit 6655dfe

Please sign in to comment.