-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix issue with apply on empty DataFrame #28213
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
Changes from 10 commits
444209d
b749cca
d9b620b
a82479a
aa4b33b
61f432f
cb68153
f4c7a97
633a6b8
1993c7c
a0c09eb
51de6ef
91ef657
4a9ea0b
42b2209
de0e1dd
6b98060
9d6ae49
2067c1a
9442a04
20a3199
f3077aa
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 | ||
---|---|---|---|---|
|
@@ -204,16 +204,19 @@ def apply_empty_result(self): | |||
from pandas import Series | ||||
|
||||
if not reduce: | ||||
|
||||
EMPTY_SERIES = Series([]) | ||||
try: | ||||
r = self.f(EMPTY_SERIES, *self.args, **self.kwds) | ||||
r = self.f(Series([])) | ||||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
reduce = not isinstance(r, Series) | ||||
except Exception: | ||||
pass | ||||
|
||||
if reduce: | ||||
return self.obj._constructor_sliced(np.nan, index=self.agg_axis) | ||||
if len(self.agg_axis): | ||||
r = self.f(Series([])) | ||||
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. pass args & 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. we already are trying to reduce above (line 208), why are you calling the function again? does this hit the Except? 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 did that in case 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 am still puzzled why you can not pass args/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 what's happening is the function Line 109 in cb68153
df.nunique() test):
because at that point 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. Was confused by this to but I think this makes sense. I suppose this was hitting the |
||||
else: | ||||
r = np.nan | ||||
|
||||
return self.obj._constructor_sliced(r, index=self.agg_axis) | ||||
else: | ||||
return self.obj.copy() | ||||
|
||||
|
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.
this is specific to
np.*
and.nunique()
? if so can you be more specificThere 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.
I think it'd apply to any reduction whose output isn't empty when the input is, should I say something to that effect?