Skip to content

BUG: rolling aggregate() with a list of functions along axis 1 raises ValueError #46132 #46892

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
wants to merge 17 commits into from

Conversation

xr-chen
Copy link
Contributor

@xr-chen xr-chen commented Apr 28, 2022

xr-chen added 2 commits April 28, 2022 15:36
rolling aggregate() with a list of functions along axis 1 raise ValueError
@jreback jreback changed the title Bug: GH46132 BUG: rolling aggregate() with a list of functions along axis 1 raises ValueError #46132 Apr 29, 2022
@jreback jreback added Window rolling, ewma, expanding Bug labels Apr 29, 2022
@jreback
Copy link
Contributor

jreback commented Apr 29, 2022

can you merge master and resolve conflicts

@xr-chen
Copy link
Contributor Author

xr-chen commented Apr 30, 2022

@github-actions pre-commit

@pep8speaks
Copy link

pep8speaks commented Apr 30, 2022

Hello @xr-chen! 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 2022-06-05 20:54:19 UTC

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Looks great overall. One comment otherwise LGTM

_axis_modifed_flag = False
# modifying axis and transposing dataframe should not be needed
# once ReamplerWindow supports axis = 1
if self.axis == 1:
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we not using the _get_data_to_aggregate pattern here? this seems like making yet another way to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you mean to write another function or use some methods in some python class to get the data ready for aggregation?

Copy link
Member

Choose a reason for hiding this comment

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

_get_data_to_aggregate pattern was never implemented on rolling, just groupby.

Maybe instead @xr-chen, could you try to investigate assigning ResamplerWindowApply's self.axis attribute like GroupByApply fixes this instead?

self.axis = obj.obj._get_axis_number(kwargs.get("axis", 0))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your suggestion. I will have a try.

Copy link
Contributor Author

@xr-chen xr-chen May 17, 2022

Choose a reason for hiding this comment

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

I have tried to initialize ResamperWindowApply's self.axis like in GroupByApply, but that doesn't work. The agg_list_like method of Apply class behaves the same whatever the self.axis is, and it still calls obj._gotitem with subset as a Series and self.axis=1 which finally causes an error. @mroeschke

@xr-chen xr-chen requested a review from jreback June 5, 2022 22:25
self.axis = 0

try:
result = ResamplerWindowApply(self, func, args=args, kwargs=kwargs).agg()
Copy link
Contributor

Choose a reason for hiding this comment

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

can we just add an axis argument here and thread it thru. this state change is not at all obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just would like to make sure if you want me to make this comment more clear? And I notice that in PR #47078, it says rolling window doesn't support axis = 1 anymore and that caused this change didn't pass the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

i am not sure what you mean. I don't really like this approach because its hiding the axis state. What I am suggesting is we actually fix this by passing thru the axis argument to do this properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, the agg method of ResamplerWindowApply hasn't been implemented, yet, and it will call the agg method of Apply class which can't recognize that we want to agg on axis=1 instead of axis=0. Even though I am not entirely familiar with pandas, I think passing the axis argument could not help.

@xr-chen xr-chen closed this Jun 6, 2022
@xr-chen xr-chen deleted the bug_46132 branch June 6, 2022 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: rolling aggregate() with a list of functions along axis 1 raises ValueError
4 participants