@@ -1106,76 +1106,6 @@ def f(self, other):
11061106# Sparse
11071107
11081108
1109- def _cast_sparse_series_op (left , right , opname ):
1110- """
1111- For SparseSeries operation, coerce to float64 if the result is expected
1112- to have NaN or inf values
1113-
1114- Parameters
1115- ----------
1116- left : SparseArray
1117- right : SparseArray
1118- opname : str
1119-
1120- Returns
1121- -------
1122- left : SparseArray
1123- right : SparseArray
1124- """
1125- from pandas .core .sparse .api import SparseDtype
1126-
1127- opname = opname .strip ("_" )
1128-
1129- # TODO: This should be moved to the array?
1130- if is_integer_dtype (left ) and is_integer_dtype (right ):
1131- # series coerces to float64 if result should have NaN/inf
1132- if opname in ("floordiv" , "mod" ) and (right .to_dense () == 0 ).any ():
1133- left = left .astype (SparseDtype (np .float64 , left .fill_value ))
1134- right = right .astype (SparseDtype (np .float64 , right .fill_value ))
1135- elif opname in ("rfloordiv" , "rmod" ) and (left .to_dense () == 0 ).any ():
1136- left = left .astype (SparseDtype (np .float64 , left .fill_value ))
1137- right = right .astype (SparseDtype (np .float64 , right .fill_value ))
1138-
1139- return left , right
1140-
1141-
1142- def _arith_method_SPARSE_SERIES (cls , op , special ):
1143- """
1144- Wrapper function for Series arithmetic operations, to avoid
1145- code duplication.
1146- """
1147- op_name = _get_op_name (op , special )
1148-
1149- def wrapper (self , other ):
1150- if isinstance (other , ABCDataFrame ):
1151- return NotImplemented
1152- elif isinstance (other , ABCSeries ):
1153- return _sparse_series_op (self , other , op , op_name )
1154- elif is_scalar (other ):
1155- with np .errstate (all = "ignore" ):
1156- new_values = op (self .values , other )
1157- return self ._constructor (new_values , index = self .index , name = self .name )
1158- else : # pragma: no cover
1159- raise TypeError (
1160- "operation with {other} not supported" .format (other = type (other ))
1161- )
1162-
1163- wrapper .__name__ = op_name
1164- return wrapper
1165-
1166-
1167- def _sparse_series_op (left , right , op , name ):
1168- left , right = left .align (right , join = "outer" , copy = False )
1169- new_index = left .index
1170- new_name = get_op_result_name (left , right )
1171-
1172- from pandas .core .arrays .sparse import _sparse_array_op
1173-
1174- lvalues , rvalues = _cast_sparse_series_op (left .values , right .values , name )
1175- result = _sparse_array_op (lvalues , rvalues , op , name )
1176- return left ._constructor (result , index = new_index , name = new_name )
1177-
1178-
11791109def maybe_dispatch_ufunc_to_dunder_op (
11801110 self : ArrayLike , ufunc : Callable , method : str , * inputs : ArrayLike , ** kwargs : Any
11811111):
0 commit comments