File tree 2 files changed +12
-8
lines changed
2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -199,6 +199,7 @@ Performance improvements
199
199
- Performance improvement in :class: `Series ` reductions (:issue: `52341 `)
200
200
- Performance improvement in :meth: `Series.to_numpy ` when dtype is a numpy float dtype and ``na_value `` is ``np.nan `` (:issue: `52430 `)
201
201
- Performance improvement in :meth: `Series.corr ` and :meth: `Series.cov ` for extension dtypes (:issue: `52502 `)
202
+ - Performance improvement in :meth: `~arrays.ArrowExtensionArray.to_numpy ` (:issue: `52525 `)
202
203
-
203
204
204
205
.. ---------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -1046,18 +1046,21 @@ def to_numpy(
1046
1046
mask = ~ self .isna ()
1047
1047
result [mask ] = np .asarray (self [mask ]._pa_array )
1048
1048
elif pa .types .is_null (self ._pa_array .type ):
1049
- result = np .asarray (self ._pa_array , dtype = dtype )
1050
- if not isna (na_value ):
1051
- result [:] = na_value
1052
- return result
1049
+ fill_value = None if isna (na_value ) else na_value
1050
+ return np .full (len (self ), fill_value = fill_value , dtype = dtype )
1053
1051
elif self ._hasna :
1054
- data = self .copy ()
1055
- data [self .isna ()] = na_value
1056
- return np .asarray (data ._pa_array , dtype = dtype )
1052
+ data = self .fillna (na_value )
1053
+ result = data ._pa_array .to_numpy ()
1054
+ if dtype is not None :
1055
+ result = result .astype (dtype , copy = False )
1056
+ return result
1057
1057
else :
1058
- result = np .asarray (self ._pa_array , dtype = dtype )
1058
+ result = self ._pa_array .to_numpy ()
1059
+ if dtype is not None :
1060
+ result = result .astype (dtype , copy = False )
1059
1061
if copy :
1060
1062
result = result .copy ()
1063
+ return result
1061
1064
if self ._hasna :
1062
1065
result [self .isna ()] = na_value
1063
1066
return result
You can’t perform that action at this time.
0 commit comments