|
12 | 12 | )
|
13 | 13 | from pandas._typing import (
|
14 | 14 | Dtype,
|
15 |
| - NpDtype, |
16 | 15 | Scalar,
|
17 | 16 | npt,
|
18 | 17 | )
|
@@ -151,31 +150,6 @@ def dtype(self) -> StringDtype: # type: ignore[override]
|
151 | 150 | """
|
152 | 151 | return self._dtype
|
153 | 152 |
|
154 |
| - def __array__(self, dtype: NpDtype | None = None) -> np.ndarray: |
155 |
| - """Correctly construct numpy arrays when passed to `np.asarray()`.""" |
156 |
| - return self.to_numpy(dtype=dtype) |
157 |
| - |
158 |
| - def to_numpy( |
159 |
| - self, |
160 |
| - dtype: npt.DTypeLike | None = None, |
161 |
| - copy: bool = False, |
162 |
| - na_value=lib.no_default, |
163 |
| - ) -> np.ndarray: |
164 |
| - """ |
165 |
| - Convert to a NumPy ndarray. |
166 |
| - """ |
167 |
| - # TODO: copy argument is ignored |
168 |
| - |
169 |
| - result = np.array(self._data, dtype=dtype) |
170 |
| - if self._data.null_count > 0: |
171 |
| - if na_value is lib.no_default: |
172 |
| - if dtype and np.issubdtype(dtype, np.floating): |
173 |
| - return result |
174 |
| - na_value = self._dtype.na_value |
175 |
| - mask = self.isna() |
176 |
| - result[mask] = na_value |
177 |
| - return result |
178 |
| - |
179 | 153 | def insert(self, loc: int, item) -> ArrowStringArray:
|
180 | 154 | if not isinstance(item, str) and item is not libmissing.NA:
|
181 | 155 | raise TypeError("Scalar must be NA or str")
|
@@ -219,10 +193,11 @@ def astype(self, dtype, copy: bool = True):
|
219 | 193 | if copy:
|
220 | 194 | return self.copy()
|
221 | 195 | return self
|
222 |
| - |
223 | 196 | elif isinstance(dtype, NumericDtype):
|
224 | 197 | data = self._data.cast(pa.from_numpy_dtype(dtype.numpy_dtype))
|
225 | 198 | return dtype.__from_arrow__(data)
|
| 199 | + elif isinstance(dtype, np.dtype) and np.issubdtype(dtype, np.floating): |
| 200 | + return self.to_numpy(dtype=dtype, na_value=np.nan) |
226 | 201 |
|
227 | 202 | return super().astype(dtype, copy=copy)
|
228 | 203 |
|
|
0 commit comments