Skip to content

Commit

Permalink
Cast numpy scalars as python scalars before arith ops
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Oct 30, 2023
1 parent 1f94724 commit 6fb901c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pandas/core/ops/array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,14 @@ def maybe_prepare_scalar_for_op(obj, shape: Shape):
# np.timedelta64(3, 'D') / 2 == np.timedelta64(1, 'D')
return Timedelta(obj)

# We want NumPy numeric scalars to behave like Python scalars
# post NEP 50
elif isinstance(obj, np.integer):
return int(obj)

elif isinstance(obj, np.floating):
return float(obj)

return obj


Expand Down

0 comments on commit 6fb901c

Please sign in to comment.