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

Reorder tests in maybe_downcast_numeric #55825

Merged
merged 7 commits into from
Nov 22, 2023
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
14 changes: 5 additions & 9 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,11 @@ def trans(x):
# if we don't have any elements, just astype it
return trans(result).astype(dtype)

# do a test on the first element, if it fails then we are done
r = result.ravel()
arr = np.array([r[0]])

if isna(arr).any():
# if we have any nulls, then we are done
return result

elif not isinstance(r[0], (np.integer, np.floating, int, float, bool)):
if isinstance(result, np.ndarray):
rhshadrach marked this conversation as resolved.
Show resolved Hide resolved
element = result.item(0)
else:
element = result.iloc[0]
if not isinstance(element, (np.integer, np.floating, int, float, bool)):
# a comparable, e.g. a Decimal may slip in here
return result

Expand Down
Loading