BUG: DataFrame.agg and apply with 'size' returns a scalar#39935
BUG: DataFrame.agg and apply with 'size' returns a scalar#39935jreback merged 7 commits intopandas-dev:masterfrom
Conversation
rhshadrach
commented
Feb 20, 2021
- closes BUG: DataFrame.agg and apply with 'size' returns a scalar #39934
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
jreback
left a comment
There was a problem hiding this comment.
rebase as well.
It might be better to detect this argument 'size' and do a translation in
pandas/core/base.py: _builtin_table
|
|
||
| obj = self.obj | ||
|
|
||
| if f == "size" and isinstance(obj, ABCDataFrame): |
There was a problem hiding this comment.
doesn't this affect Series as well?
There was a problem hiding this comment.
For a Series, size gives the number of rows and so the default path calling obj.size produces the correct result.
|
@jreback - I merged master.
This isn't a builtin; |
|
my point is to map this to a lambda function to avoid special casing like this |
|
@jreback - makes sense, and I agree your suggestion is the prefered way. The one issue is that when replacing
It seems easier and less error-prone to go with 1, but I can do 2 here if you prefer. |
yeah happy to do this in the future. 2 sounds interesting actually. why don't you add a TODO for now (and issue) then can merge this one. |
|
@jreback TODO added, issue opened, and green(ish - failure is unrelated). |
|
can you merge master & ping on greenish |
…g_size � Conflicts: � pandas/tests/apply/test_frame_apply.py
|
thanks @rhshadrach |
| if f == "size" and isinstance(obj, ABCDataFrame): | ||
| # Special-cased because DataFrame.size returns a single scalar | ||
| value = obj.shape[self.axis] | ||
| return obj._constructor_sliced(value, index=self.agg_axis, name="size") |
There was a problem hiding this comment.
Is it intentional to set the name here? This isn't consistent with other string agg methods