File tree 2 files changed +9
-12
lines changed
2 files changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -516,12 +516,15 @@ def to_numpy(
516
516
# to_numpy on StringArray backed by StringDType should still return object dtype
517
517
# for backwards compat
518
518
array = self ._ndarray
519
- if dtype is None and self ._ndarray .dtype .kind == "T" :
520
- dtype = object
521
- result = np .asarray (array , dtype = dtype )
519
+ if self ._ndarray .dtype .kind == "T" :
520
+ array = array .astype (object )
522
521
if na_value is not lib .no_default and mask .any ():
523
- result = result .copy ()
522
+ result = array .copy ()
524
523
result [mask ] = na_value
524
+ else :
525
+ result = self ._ndarray
526
+
527
+ result = np .asarray (result , dtype = dtype )
525
528
526
529
if copy and result is self ._ndarray :
527
530
result = result .copy ()
Original file line number Diff line number Diff line change 18
18
NaTType ,
19
19
iNaT ,
20
20
lib ,
21
- missing as libmissing ,
22
21
)
23
22
from pandas ._typing import (
24
23
ArrayLike ,
32
31
npt ,
33
32
)
34
33
from pandas .compat ._optional import import_optional_dependency
35
- from pandas .compat .numpy import np_version_gt2
36
34
37
35
from pandas .core .dtypes .common import (
38
36
is_complex ,
@@ -153,12 +151,8 @@ def f(
153
151
154
152
155
153
def _bn_ok_dtype (dtype : DtypeObj , name : str ) -> bool :
156
- # Bottleneck chokes on datetime64, PeriodDtype (or and EA)
157
- if (
158
- dtype != object
159
- and (np_version_gt2 and dtype != np .dtypes .StringDType (na_object = libmissing .NA ))
160
- and not needs_i8_conversion (dtype )
161
- ):
154
+ # Bottleneck chokes on datetime64, numpy strins, PeriodDtype (or and EA)
155
+ if dtype != object and dtype .kind != "T" and not needs_i8_conversion (dtype ):
162
156
# GH 42878
163
157
# Bottleneck uses naive summation leading to O(n) loss of precision
164
158
# unlike numpy which implements pairwise summation, which has O(log(n)) loss
You can’t perform that action at this time.
0 commit comments