Skip to content
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

Small typo in apply.py #20058

Merged
merged 1 commit into from
Mar 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix typo in apply.py
  • Loading branch information
mroeschke committed Mar 9, 2018
commit 46a547d99e08d103c6c7d995215ca472e657378e
2 changes: 1 addition & 1 deletion pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def apply_broadcast(self, target):

for i, col in enumerate(target.columns):
res = self.f(target[col])
ares = np. asarray(res).ndim
Copy link
Member

Choose a reason for hiding this comment

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

Are we even hitting this block of code if we managed to get away with that!?

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't looked at the apply tests closely, but I was somewhat surprised this is line works with the whitespace...

In [1]: import numpy as np

In [2]: np. asarray([1, 2, 3]).ndim
Out[2]: 1

In [3]: np. asarray([1, 2, 3])
Out[3]: array([1, 2, 3])

In [4]: np. asarray([1, 2, 3]).ndim == np.asarray([1, 2, 3]).ndim
Out[4]: True

Copy link
Member

@gfyoung gfyoung Mar 8, 2018

Choose a reason for hiding this comment

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

That's really odd! I didn't know this could work. And I thought Python was really picky about whitespace... 😄

BTW, the easiest way to check is to deliberately raise an exception in that logic block and run tests with that bugged install.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like the following tests in pandas/tests/frame/test_apply.py hit this path:

TestDataFrameApply.test_apply_broadcast_deprecated
TestDataFrameApply.test_apply_broadcast
TestDataFrameApply.test_apply_broadcast_error
TestInferOutputShape.test_result_type

ares = np.asarray(res).ndim

# must be a scalar or 1d
if ares > 1:
Expand Down