Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
simplify
  • Loading branch information
jbrockmendel committed Dec 18, 2021
commit 96a0c089c4404bfcc0da098f972e030b6db677ad
12 changes: 3 additions & 9 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,18 @@ def _sparse_array_op(
left_sp_values = left.sp_values
right_sp_values = right.sp_values

sparse_op = getattr(splib, opname)

if (
name in ["floordiv", "mod"]
and (right == 0).any()
and left.dtype.kind in ["i", "u"]
):
# Match the non-Sparse Series behavior
if name == "floordiv":
# error: Module has no attribute "sparse_floordiv_float64"
sparse_op = splib.sparse_floordiv_float64 # type: ignore[attr-defined]
else:
# error: Module has no attribute "sparse_mod_float64"
sparse_op = splib.sparse_mod_float64 # type: ignore[attr-defined]

opname = f"sparse_{name}_float64"
left_sp_values = left_sp_values.astype("float64")
right_sp_values = right_sp_values.astype("float64")

sparse_op = getattr(splib, opname)

with np.errstate(all="ignore"):
result, index, fill = sparse_op(
left_sp_values,
Expand Down