|
51 | 51 |
|
52 | 52 | import numpy as np |
53 | 53 |
|
| 54 | +from xarray.core import duck_array_ops |
54 | 55 | from xarray.core.computation import apply_ufunc |
55 | 56 | from xarray.core.types import T_DataArray |
56 | 57 |
|
@@ -2085,13 +2086,16 @@ def _get_res_multi(val, pat): |
2085 | 2086 | else: |
2086 | 2087 | # dtype MUST be object or strings can be truncated |
2087 | 2088 | # See: https://github.com/numpy/numpy/issues/8352 |
2088 | | - return self._apply( |
2089 | | - func=_get_res_multi, |
2090 | | - func_args=(pat,), |
2091 | | - dtype=np.object_, |
2092 | | - output_core_dims=[[dim]], |
2093 | | - output_sizes={dim: maxgroups}, |
2094 | | - ).astype(self._obj.dtype.kind) |
| 2089 | + return duck_array_ops.astype( |
| 2090 | + self._apply( |
| 2091 | + func=_get_res_multi, |
| 2092 | + func_args=(pat,), |
| 2093 | + dtype=np.object_, |
| 2094 | + output_core_dims=[[dim]], |
| 2095 | + output_sizes={dim: maxgroups}, |
| 2096 | + ), |
| 2097 | + self._obj.dtype.kind, |
| 2098 | + ) |
2095 | 2099 |
|
2096 | 2100 | def extractall( |
2097 | 2101 | self, |
@@ -2258,15 +2262,18 @@ def _get_res(val, ipat, imaxcount=maxcount, dtype=self._obj.dtype): |
2258 | 2262 |
|
2259 | 2263 | return res |
2260 | 2264 |
|
2261 | | - return self._apply( |
2262 | | - # dtype MUST be object or strings can be truncated |
2263 | | - # See: https://github.com/numpy/numpy/issues/8352 |
2264 | | - func=_get_res, |
2265 | | - func_args=(pat,), |
2266 | | - dtype=np.object_, |
2267 | | - output_core_dims=[[group_dim, match_dim]], |
2268 | | - output_sizes={group_dim: maxgroups, match_dim: maxcount}, |
2269 | | - ).astype(self._obj.dtype.kind) |
| 2265 | + return duck_array_ops.astype( |
| 2266 | + self._apply( |
| 2267 | + # dtype MUST be object or strings can be truncated |
| 2268 | + # See: https://github.com/numpy/numpy/issues/8352 |
| 2269 | + func=_get_res, |
| 2270 | + func_args=(pat,), |
| 2271 | + dtype=np.object_, |
| 2272 | + output_core_dims=[[group_dim, match_dim]], |
| 2273 | + output_sizes={group_dim: maxgroups, match_dim: maxcount}, |
| 2274 | + ), |
| 2275 | + self._obj.dtype.kind, |
| 2276 | + ) |
2270 | 2277 |
|
2271 | 2278 | def findall( |
2272 | 2279 | self, |
@@ -2385,13 +2392,16 @@ def _partitioner( |
2385 | 2392 |
|
2386 | 2393 | # dtype MUST be object or strings can be truncated |
2387 | 2394 | # See: https://github.com/numpy/numpy/issues/8352 |
2388 | | - return self._apply( |
2389 | | - func=arrfunc, |
2390 | | - func_args=(sep,), |
2391 | | - dtype=np.object_, |
2392 | | - output_core_dims=[[dim]], |
2393 | | - output_sizes={dim: 3}, |
2394 | | - ).astype(self._obj.dtype.kind) |
| 2395 | + return duck_array_ops.astype( |
| 2396 | + self._apply( |
| 2397 | + func=arrfunc, |
| 2398 | + func_args=(sep,), |
| 2399 | + dtype=np.object_, |
| 2400 | + output_core_dims=[[dim]], |
| 2401 | + output_sizes={dim: 3}, |
| 2402 | + ), |
| 2403 | + self._obj.dtype.kind, |
| 2404 | + ) |
2395 | 2405 |
|
2396 | 2406 | def partition( |
2397 | 2407 | self, |
@@ -2510,13 +2520,16 @@ def _dosplit(mystr, sep, maxsplit=maxsplit, dtype=self._obj.dtype): |
2510 | 2520 |
|
2511 | 2521 | # dtype MUST be object or strings can be truncated |
2512 | 2522 | # See: https://github.com/numpy/numpy/issues/8352 |
2513 | | - return self._apply( |
2514 | | - func=_dosplit, |
2515 | | - func_args=(sep,), |
2516 | | - dtype=np.object_, |
2517 | | - output_core_dims=[[dim]], |
2518 | | - output_sizes={dim: maxsplit}, |
2519 | | - ).astype(self._obj.dtype.kind) |
| 2523 | + return duck_array_ops.astype( |
| 2524 | + self._apply( |
| 2525 | + func=_dosplit, |
| 2526 | + func_args=(sep,), |
| 2527 | + dtype=np.object_, |
| 2528 | + output_core_dims=[[dim]], |
| 2529 | + output_sizes={dim: maxsplit}, |
| 2530 | + ), |
| 2531 | + self._obj.dtype.kind, |
| 2532 | + ) |
2520 | 2533 |
|
2521 | 2534 | def split( |
2522 | 2535 | self, |
|
0 commit comments