-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: df.agg, df.transform and df.apply use different methods when axis=1 than when axis=0 #21224
Changes from all commits
3d95bfc
262bd3e
ed43757
2be3747
b6382d4
5ad024c
39ced29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
from pandas.core.dtypes.generic import ABCSeries | ||
from pandas.core.dtypes.common import ( | ||
is_extension_type, | ||
is_dict_like, | ||
is_list_like, | ||
is_sequence) | ||
from pandas.util._decorators import cache_readonly | ||
|
||
|
@@ -105,6 +107,11 @@ def agg_axis(self): | |
def get_result(self): | ||
""" compute the results """ | ||
|
||
# dispatch to agg | ||
if is_list_like(self.f) or is_dict_like(self.f): | ||
return self.obj.aggregate(self.f, axis=self.axis, | ||
*self.args, **self.kwds) | ||
|
||
# all empty | ||
if len(self.columns) == 0 and len(self.index) == 0: | ||
return self.apply_empty_result() | ||
|
@@ -308,15 +315,6 @@ def wrap_results(self): | |
class FrameRowApply(FrameApply): | ||
axis = 0 | ||
|
||
def get_result(self): | ||
|
||
# dispatch to agg | ||
if isinstance(self.f, (list, dict)): | ||
return self.obj.aggregate(self.f, axis=self.axis, | ||
*self.args, **self.kwds) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return super(FrameRowApply, self).get_result() | ||
|
||
def apply_broadcast(self): | ||
return super(FrameRowApply, self).apply_broadcast(self.obj) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9193,16 +9193,14 @@ def ewm(self, com=None, span=None, halflife=None, alpha=None, | |
|
||
cls.ewm = ewm | ||
|
||
@Appender(_shared_docs['transform'] % _shared_doc_kwargs) | ||
def transform(self, func, *args, **kwargs): | ||
result = self.agg(func, *args, **kwargs) | ||
if is_scalar(result) or len(result) != len(self): | ||
raise ValueError("transforms cannot produce " | ||
"aggregated results") | ||
@Appender(_shared_docs['transform'] % _shared_doc_kwargs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to add this appender in frame.py as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'll do that |
||
def transform(self, func, *args, **kwargs): | ||
result = self.agg(func, *args, **kwargs) | ||
if is_scalar(result) or len(result) != len(self): | ||
raise ValueError("transforms cannot produce " | ||
"aggregated results") | ||
|
||
return result | ||
|
||
cls.transform = transform | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when transform was added by calling |
||
return result | ||
|
||
# ---------------------------------------------------------------------- | ||
# Misc methods | ||
|
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.
maybe also add axis_frame just for consistency? (its exactly equal to axis)
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.
sure, ok