Skip to content

BUG: add reset logic for Grouper if new obj is passed in (#26564) #29800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 change: 0 additions & 1 deletion pandas/core/groupby/grouper.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def __init__(self, key=None, level=None, freq=None, axis=0, sort=False):
self.freq = freq
self.axis = axis
self.sort = sort

self.grouper = None
self.obj = None
self.indexer = None
Expand Down
33 changes: 33 additions & 0 deletions pandas/tests/resample/test_resampler_grouper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from textwrap import dedent

import numpy as np
import pytest

from pandas.util._test_decorators import async_mark

Expand Down Expand Up @@ -295,3 +296,35 @@ def test_median_duplicate_columns():
result = df.resample("5s").median()
expected.columns = result.columns
tm.assert_frame_equal(result, expected)


@pytest.mark.xfail(reason="marked as xfail for: #26564")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

giving a GH reference is good, but the rest of this doesnt give much information. is there a single-line description that a reader would find informative?

can you add a "GH" in front of the "#" pls

ca

def test_same_grouper_on_different_frames():

df1 = pd.DataFrame(
[["a", 1, 2], ["a", 4, 5], ["b", 2, 3]], columns=["type", "num1", "num2"],
)
df1["date"] = pd.to_datetime(["05/29/2019", "05/28/2019", "05/27/2019"])

df2 = pd.DataFrame([["c", 6, 7], ["d", 8, 9]], columns=["type", "num1", "num2"],)
df2["date"] = pd.to_datetime(["02/12/2018", "03/13/2018"])

groupbys = ["type", pd.Grouper(key="date", freq="1D")]

df1.groupby(groupbys).sum()
result = df2.groupby(groupbys).count()

expected = pd.DataFrame(
{
"num1": {
("c", Timestamp("2018-02-12 00:00:00", freq="D")): 1,
("d", Timestamp("2018-03-13 00:00:00", freq="D")): 1,
},
"num2": {
("c", Timestamp("2018-02-12 00:00:00", freq="D")): 1,
("d", Timestamp("2018-03-13 00:00:00", freq="D")): 1,
},
}
)
expected.index.set_names(["type", "date"], inplace=True)
tm.assert_frame_equal(result, expected)