-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: Fix TypeError in groupby min / max of period column #31477
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
Conversation
pandas/tests/groupby/test_groupby.py
Outdated
@@ -2037,3 +2037,19 @@ def test_groupby_list_level(): | |||
expected = pd.DataFrame(np.arange(0, 9).reshape(3, 3)) | |||
result = expected.groupby(level=[0]).mean() | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
|
|||
@pytest.mark.parametrize("func", ["min", "max"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should go to test_aggregate
doc/source/whatsnew/v1.1.0.rst
Outdated
@@ -179,6 +179,7 @@ Groupby/resample/rolling | |||
|
|||
- Bug in :meth:`GroupBy.apply` raises ``ValueError`` when the ``by`` axis is not sorted and has duplicates and the applied ``func`` does not mutate passed in objects (:issue:`30667`) | |||
- Bug in :meth:`DataFrameGroupby.transform` produces incorrect result with transformation functions (:issue:`30918`) | |||
- Bug in :meth:`DataFrame.groupby` whereby taking the minimum or maximum of a column with period dtype would raise a ``TypeError``. (:issue:`31471`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this to the 1.01 whatsnew file? (this is a regression)
pandas/tests/groupby/test_groupby.py
Outdated
|
||
df = pd.DataFrame({"a": groups, "b": periods}) | ||
|
||
result = getattr(df.groupby("a")["b"], func)() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add a test for the version on the dataframe? (so without the ["b"]
column selection)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good @dsaxton some comments, ping on green.
@@ -684,6 +684,34 @@ def aggfunc(x): | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
|
|||
@pytest.mark.parametrize("func", ["min", "max"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move these to test_timegrouper.py (same dir)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're grouping by an int column and only aggregating the period column (not using a time grouper), does the current location make more sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This location seems OK since we're grouping by integers, not time.
@@ -684,6 +684,34 @@ def aggfunc(x): | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
|
|||
@pytest.mark.parametrize("func", ["min", "max"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This location seems OK since we're grouping by integers, not time.
@dsaxton can you fix the merge conflict in the release notes? |
Thanks! |
…x of period column
…d column (#31671) Co-authored-by: Daniel Saxton <[email protected]>
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff