@@ -181,9 +181,8 @@ def _sparse_array_op(
181181 ltype = SparseDtype (subtype , left .fill_value )
182182 rtype = SparseDtype (subtype , right .fill_value )
183183
184- # TODO(GH-23092): pass copy=False. Need to fix astype_nansafe
185- left = left .astype (ltype )
186- right = right .astype (rtype )
184+ left = left .astype (ltype , copy = False )
185+ right = right .astype (rtype , copy = False )
187186 dtype = ltype .subtype
188187 else :
189188 dtype = ltype
@@ -233,6 +232,15 @@ def _sparse_array_op(
233232 right .fill_value ,
234233 )
235234
235+ if name == "divmod" :
236+ # result is a 2-tuple
237+ # error: Incompatible return value type (got "Tuple[SparseArray,
238+ # SparseArray]", expected "SparseArray")
239+ return ( # type: ignore[return-value]
240+ _wrap_result (name , result [0 ], index , fill [0 ], dtype = result_dtype ),
241+ _wrap_result (name , result [1 ], index , fill [1 ], dtype = result_dtype ),
242+ )
243+
236244 if result_dtype is None :
237245 result_dtype = result .dtype
238246
@@ -1224,30 +1232,8 @@ def astype(self, dtype: AstypeArg | None = None, copy: bool = True):
12241232 else :
12251233 return self .copy ()
12261234 dtype = self .dtype .update_dtype (dtype )
1227- # error: Item "ExtensionDtype" of "Union[ExtensionDtype, str, dtype[Any],
1228- # Type[str], Type[float], Type[int], Type[complex], Type[bool], Type[object],
1229- # None]" has no attribute "_subtype_with_str"
1230- # error: Item "str" of "Union[ExtensionDtype, str, dtype[Any], Type[str],
1231- # Type[float], Type[int], Type[complex], Type[bool], Type[object], None]" has no
1232- # attribute "_subtype_with_str"
1233- # error: Item "dtype[Any]" of "Union[ExtensionDtype, str, dtype[Any], Type[str],
1234- # Type[float], Type[int], Type[complex], Type[bool], Type[object], None]" has no
1235- # attribute "_subtype_with_str"
1236- # error: Item "ABCMeta" of "Union[ExtensionDtype, str, dtype[Any], Type[str],
1237- # Type[float], Type[int], Type[complex], Type[bool], Type[object], None]" has no
1238- # attribute "_subtype_with_str"
1239- # error: Item "type" of "Union[ExtensionDtype, str, dtype[Any], Type[str],
1240- # Type[float], Type[int], Type[complex], Type[bool], Type[object], None]" has no
1241- # attribute "_subtype_with_str"
1242- # error: Item "None" of "Union[ExtensionDtype, str, dtype[Any], Type[str],
1243- # Type[float], Type[int], Type[complex], Type[bool], Type[object], None]" has no
1244- # attribute "_subtype_with_str"
1245- subtype = pandas_dtype (dtype ._subtype_with_str ) # type: ignore[union-attr]
1246- # TODO copy=False is broken for astype_nansafe with int -> float, so cannot
1247- # passthrough copy keyword: https://github.com/pandas-dev/pandas/issues/34456
1248- sp_values = astype_nansafe (self .sp_values , subtype , copy = True )
1249- if sp_values is self .sp_values and copy :
1250- sp_values = sp_values .copy ()
1235+ subtype = pandas_dtype (dtype ._subtype_with_str )
1236+ sp_values = astype_nansafe (self .sp_values , subtype , copy = copy )
12511237
12521238 # error: Argument 1 to "_simple_new" of "SparseArray" has incompatible type
12531239 # "ExtensionArray"; expected "ndarray"
@@ -1646,7 +1632,6 @@ def _arith_method(self, other, op):
16461632 else :
16471633 other = np .asarray (other )
16481634 with np .errstate (all = "ignore" ):
1649- # TODO: look into _wrap_result
16501635 if len (self ) != len (other ):
16511636 raise AssertionError (
16521637 f"length mismatch: { len (self )} vs. { len (other )} "
0 commit comments