Skip to content

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

Merged
merged 13 commits into from
Feb 4, 2020
Merged

REGR: Fix TypeError in groupby min / max of period column #31477

merged 13 commits into from
Feb 4, 2020

Conversation

dsaxton
Copy link
Member

@dsaxton dsaxton commented Jan 31, 2020

@pep8speaks
Copy link

pep8speaks commented Jan 31, 2020

Hello @dsaxton! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-02-04 21:30:21 UTC

@@ -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"])
Copy link
Contributor

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

@jorisvandenbossche jorisvandenbossche added Regression Functionality that used to work in a prior pandas version and removed Bug labels Jan 31, 2020
@jorisvandenbossche jorisvandenbossche added this to the 1.0.1 milestone Jan 31, 2020
@@ -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`)
Copy link
Member

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)


df = pd.DataFrame({"a": groups, "b": periods})

result = getattr(df.groupby("a")["b"], func)()
Copy link
Member

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)

@dsaxton dsaxton changed the title BUG: Fix TypeError in groupby min / max of period column REGR: Fix TypeError in groupby min / max of period column Jan 31, 2020
Copy link
Contributor

@jreback jreback left a 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"])
Copy link
Contributor

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)

Copy link
Member Author

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?

Copy link
Contributor

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"])
Copy link
Contributor

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.

@TomAugspurger
Copy link
Contributor

@dsaxton can you fix the merge conflict in the release notes?

@TomAugspurger TomAugspurger merged commit c3e32d7 into pandas-dev:master Feb 4, 2020
@TomAugspurger
Copy link
Contributor

Thanks!

@dsaxton dsaxton deleted the period-bug branch February 4, 2020 22:54
jreback pushed a commit that referenced this pull request Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError when calculating min/max of period column using groupby
5 participants