Skip to content
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

TST: groupby apply called multiple times #34897

Merged
merged 7 commits into from
Jun 20, 2020

Conversation

Rohith295
Copy link
Contributor

@Rohith295 Rohith295 commented Jun 20, 2020

closes #31111
xref #24748

  • tests added / passed
  • passes black pandas
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • [ Added test for testing func should be called len(set(groupby_column)) times when passed to groupby.apply(func) ] whatsnew entry

@pep8speaks
Copy link

pep8speaks commented Jun 20, 2020

Hello @Rohith295! 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-06-20 14:58:22 UTC

@jreback jreback changed the title Added test for #GH31111 TST: groupby apply behaviour Jun 20, 2020
Copy link
Member

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

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

Thanks @Rohith295 ! Seems there's some linting failures, can you run black and flake8 against your changed file?

def test_apply_function_called_count(capsys):
# GH: 31111
# groupby-apply need to execute len(set(group_by_columns)) times
# `https://github.com/pandas-dev/pandas/issues/31111`
Copy link
Member

Choose a reason for hiding this comment

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

If you already have the issue number you don't need the link as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. I understood that. Will make sure not to repeat this again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed accordingly. @MarcoGorelli

# `https://github.com/pandas-dev/pandas/issues/31111`


function_called_count = 2 # Number of times `apply` should call a function for the current test
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps call this expected, and call capsys.readouterr().out.count("function_called") result, and at the end do assert result == expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I will make it more readable.

@charlesdong1991 charlesdong1991 added Testing pandas testing functions or related to the test suite Apply Apply, Aggregate, Transform, Map Groupby labels Jun 20, 2020
@@ -974,3 +974,24 @@ def test_apply_function_with_indexing_return_column():
result = df.groupby("foo1", as_index=False).apply(lambda x: x.mean())
expected = DataFrame({"foo1": ["one", "three", "two"], "foo2": [3.0, 4.0, 4.0]})
tm.assert_frame_equal(result, expected)


def test_apply_function_called_count(capsys):
Copy link
Contributor

Choose a reason for hiding this comment

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

move this near test_group_apply_once_per_group and indicate the same issue number (as well)

Copy link
Contributor

Choose a reason for hiding this comment

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

and rename these test to test_group_apply_once_per_group2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright @jreback . Will change it accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should remove GH: 31111 and use # GH2936, GH7739, GH10519, GH2656, GH12155, GH20084, GH21417 @jreback

Copy link
Contributor

Choose a reason for hiding this comment

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

you can add this issue number as well is ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. fixed accordingly

@jreback jreback changed the title TST: groupby apply behaviour TST: groupby apply called multiple times Jun 20, 2020
@jreback
Copy link
Contributor

jreback commented Jun 20, 2020

this is very similar to these issues
GH2936, GH7739, GH10519, GH2656, GH12155, GH20084, GH21417
which are now fixed

@jreback jreback added this to the 1.1 milestone Jun 20, 2020
@jreback
Copy link
Contributor

jreback commented Jun 20, 2020

lgtm ping on green.

@jreback jreback merged commit dab4d88 into pandas-dev:master Jun 20, 2020
@jreback
Copy link
Contributor

jreback commented Jun 20, 2020

thanks @Rohith295

@Rohith295 Rohith295 deleted the GroupByApplyBehaviour-31111 branch June 21, 2020 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Groupby Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strange groupby apply behaviour
5 participants