Skip to content

CLN: Clean groupby tests #36925

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

Merged
merged 1 commit into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ def test_attr_wrapper(ts):
# get attribute
result = grouped.dtype
expected = grouped.agg(lambda x: x.dtype)
tm.assert_series_equal(result, expected)

# make sure raises error
msg = "'SeriesGroupBy' object has no attribute 'foo'"
Expand Down Expand Up @@ -1503,7 +1504,7 @@ def test_groupby_reindex_inside_function():
ind = date_range(start="2012/1/1", freq="5min", periods=periods)
df = DataFrame({"high": np.arange(periods), "low": np.arange(periods)}, index=ind)

def agg_before(hour, func, fix=False):
def agg_before(func, fix=False):
"""
Run an aggregate func on the subset of data.
"""
Expand All @@ -1518,13 +1519,9 @@ def _func(data):

return _func

def afunc(data):
d = data.select(lambda x: x.hour < 11).dropna()
return np.max(d)

grouped = df.groupby(lambda x: datetime(x.year, x.month, x.day))
closure_bad = grouped.agg({"high": agg_before(11, np.max)})
closure_good = grouped.agg({"high": agg_before(11, np.max, True)})
closure_bad = grouped.agg({"high": agg_before(np.max)})
closure_good = grouped.agg({"high": agg_before(np.max, True)})

tm.assert_frame_equal(closure_bad, closure_good)

Expand Down
1 change: 0 additions & 1 deletion pandas/tests/groupby/test_groupby_dropna.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ def test_slice_groupby_then_transform(dropna, df_expected, s_expected):
res = gb_slice.transform(len)
tm.assert_frame_equal(res, df_expected)

gb_slice = gb["B"]
res = gb["B"].transform(len)
tm.assert_series_equal(res, s_expected)

Expand Down