File tree Expand file tree Collapse file tree 2 files changed +9
-12
lines changed Expand file tree Collapse file tree 2 files changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -516,12 +516,15 @@ def to_numpy(
516516 # to_numpy on StringArray backed by StringDType should still return object dtype
517517 # for backwards compat
518518 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 )
522521 if na_value is not lib .no_default and mask .any ():
523- result = result .copy ()
522+ result = array .copy ()
524523 result [mask ] = na_value
524+ else :
525+ result = self ._ndarray
526+
527+ result = np .asarray (result , dtype = dtype )
525528
526529 if copy and result is self ._ndarray :
527530 result = result .copy ()
Original file line number Diff line number Diff line change 1818 NaTType ,
1919 iNaT ,
2020 lib ,
21- missing as libmissing ,
2221)
2322from pandas ._typing import (
2423 ArrayLike ,
3231 npt ,
3332)
3433from pandas .compat ._optional import import_optional_dependency
35- from pandas .compat .numpy import np_version_gt2
3634
3735from pandas .core .dtypes .common import (
3836 is_complex ,
@@ -153,12 +151,8 @@ def f(
153151
154152
155153def _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 ):
162156 # GH 42878
163157 # Bottleneck uses naive summation leading to O(n) loss of precision
164158 # unlike numpy which implements pairwise summation, which has O(log(n)) loss
You can’t perform that action at this time.
0 commit comments