@@ -181,9 +181,8 @@ def _sparse_array_op(
181
181
ltype = SparseDtype (subtype , left .fill_value )
182
182
rtype = SparseDtype (subtype , right .fill_value )
183
183
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 )
187
186
dtype = ltype .subtype
188
187
else :
189
188
dtype = ltype
@@ -233,6 +232,15 @@ def _sparse_array_op(
233
232
right .fill_value ,
234
233
)
235
234
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
+
236
244
if result_dtype is None :
237
245
result_dtype = result .dtype
238
246
@@ -1224,30 +1232,8 @@ def astype(self, dtype: AstypeArg | None = None, copy: bool = True):
1224
1232
else :
1225
1233
return self .copy ()
1226
1234
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 )
1251
1237
1252
1238
# error: Argument 1 to "_simple_new" of "SparseArray" has incompatible type
1253
1239
# "ExtensionArray"; expected "ndarray"
@@ -1646,7 +1632,6 @@ def _arith_method(self, other, op):
1646
1632
else :
1647
1633
other = np .asarray (other )
1648
1634
with np .errstate (all = "ignore" ):
1649
- # TODO: look into _wrap_result
1650
1635
if len (self ) != len (other ):
1651
1636
raise AssertionError (
1652
1637
f"length mismatch: { len (self )} vs. { len (other )} "
0 commit comments