Skip to content

TST: corrwith and tshift in groupby/groupby.transform #32069

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

Conversation

ryankarlos
Copy link
Contributor

@ryankarlos ryankarlos commented Feb 18, 2020

This PR tests corrwith and tshift, so not sure if it fully closes the original issue or not, but the other functionsbackfill, pad and cumcount don't seem to be supported in groupby.transform as reported in issues #27472 and #31269.

@ryankarlos ryankarlos force-pushed the test-groupby-transform-fillna branch from 254ffdf to b8c622d Compare February 18, 2020 01:59
@ryankarlos ryankarlos changed the title TST: Groupby transform fillna TST: fillna in groupby transform Feb 18, 2020
@simonjayhawkins
Copy link
Member

@ryankarlos is there more to add. if not I don't think this closes the issue?

@simonjayhawkins simonjayhawkins added Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Testing pandas testing functions or related to the test suite labels Feb 18, 2020
@ryankarlos
Copy link
Contributor Author

ryankarlos commented Feb 18, 2020

@simonjayhawkins yes Im thinking of adding for tshift and corrwith - anymore ?

@simonjayhawkins
Copy link
Member

@simonjayhawkins yes Im thinking of adding for tshift and corrwith

those are explicitly mentioned in the issue, so could add here or seperate PRs and change the OP of this PR to xref instead of closes.

  • anymore ?

not sure. @charlesdong1991 ?

@WillAyd
Copy link
Member

WillAyd commented Feb 19, 2020

So there is already a fixture called transformation_func which has all of these; I think should be using that in tests where there is a gap today instead of adding this

@ryankarlos ryankarlos changed the title TST: fillna in groupby transform TST: corrwith, fillna and tshift in groupby Feb 23, 2020
@ryankarlos
Copy link
Contributor Author

Thanlks @WillAyd , Ive now added new tests with the transformation_func fixture.

@ryankarlos
Copy link
Contributor Author

ryankarlos commented Feb 23, 2020

@jreback @WillAyd thanks for the comments - addressed them now.

@ryankarlos ryankarlos force-pushed the test-groupby-transform-fillna branch from fdb5566 to 179046b Compare February 24, 2020 00:39
@ryankarlos ryankarlos changed the title TST: corrwith, fillna and tshift in groupby TST: corrwith, fillna and tshift in groupby/groupby.transform Feb 24, 2020
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

@ryankarlos there is a test, test_transform_transformation_func on L321 that was added recently. Should these be included there or at least co-located with that test?

@simonjayhawkins
Copy link
Member

@simonjayhawkins yes Im thinking of adding for tshift and corrwith - anymore ?

looking at

if transformation_func in ["pad", "backfill", "tshift", "corrwith", "cumcount"]:
# These transformation functions are not yet covered in this test
pytest.xfail("See GH 31269 and GH 31270")

it appears that pad and cumcount need to be tested also.

@ryankarlos
Copy link
Contributor Author

ryankarlos commented Feb 24, 2020

@simonjayhawkins yes Im thinking of adding for tshift and corrwith - anymore ?

looking at

if transformation_func in ["pad", "backfill", "tshift", "corrwith", "cumcount"]:
# These transformation functions are not yet covered in this test
pytest.xfail("See GH 31269 and GH 31270")

it appears that pad and cumcount need to be tested also.

So these other functions were throwing AttributeError when used with transform which are also mentioned in issues #31269 and #27472

@ryankarlos ryankarlos force-pushed the test-groupby-transform-fillna branch from 0dfe209 to 4d0fa2a Compare February 27, 2020 20:10
g = df.groupby("A")

op = lambda x: getattr(x, "corrwith")(df)
result = op(g)
Copy link
Member

Choose a reason for hiding this comment

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

this is g.corrwith(df).

should we be testing g.transform("corrwith", df) to address #27905? (which raises AttributeError: 'Series' object has no attribute 'corrwith')

g.corrwith(df) is tested in pandas\tests\groupby\test_groupby.py

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so the only instance using corrwith in test_groupby.py is in test_dup_labels_output_shape which doesn't seem to be fully testing the output of corrwith as is done here

tm.assert_frame_equal(result, expected)


def test_groupby_tshift(df_for_transformation_func):
Copy link
Member

Choose a reason for hiding this comment

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

should this test be testing g.transform("tshift", ...)?

Copy link
Contributor Author

@ryankarlos ryankarlos Feb 29, 2020

Choose a reason for hiding this comment

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

The output of g.transform("tshift", ...) seems to be buggy - ive just raised an issue #32344. Ive added a case for this and marked as pytest.xfail for now.

@ryankarlos ryankarlos changed the title TST: corrwith, fillna and tshift in groupby/groupby.transform TST: corrwith and tshift in groupby/groupby.transform Feb 29, 2020
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

A quick glance, it appears that with the latest changes, the tests are now not testing for expected behavior, since there are bugs that need to be fixed first. Is that correct @charlesdong1991 ?

@ryankarlos
Copy link
Contributor Author

ryankarlos commented Mar 2, 2020

@simonjayhawkins to be honest, think this original issue may be out of date and superseded by #32293 , #31269 , #27472 and #32344 reporting the associated bugs which need to be fixed first for cumcount, pad, backfill, tshift, corrwith, as seems rest of transform funcs are already tested.

If you want I could just leave the tests for groupby and put them in test_groupby.py - otherwise feel free to close this PR if not relevant anymore ?

@simonjayhawkins
Copy link
Member

otherwise feel free to close this PR if not relevant anymore ?

Thanks @ryankarlos for the work here, much appreciated, but I'll close this PR and close the issue too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Functions allowed in DataFrameGroupby.transform are not all tested
5 participants