Skip to content

Commit 78cf4d7

Browse files
authored
PERF: Improve performance for pyarrow to_numpy with na and na_value (#51439)
1 parent 89bafd2 commit 78cf4d7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pandas/core/arrays/arrow/array.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
TypeVar,
1212
cast,
1313
)
14-
import warnings
1514

1615
import numpy as np
1716

@@ -890,12 +889,13 @@ def to_numpy(
890889
result = np.empty(len(self), dtype=object)
891890
mask = ~self.isna()
892891
result[mask] = np.asarray(self[mask]._data)
892+
elif self._hasna:
893+
data = self.copy()
894+
data[self.isna()] = na_value
895+
return np.asarray(data._data, dtype=dtype)
893896
else:
894-
with warnings.catch_warnings():
895-
# int dtype with NA raises Warning
896-
warnings.filterwarnings("ignore", category=RuntimeWarning)
897-
result = np.asarray(self._data, dtype=dtype)
898-
if copy or self._hasna:
897+
result = np.asarray(self._data, dtype=dtype)
898+
if copy:
899899
result = result.copy()
900900
if self._hasna:
901901
result[self.isna()] = na_value

0 commit comments

Comments
 (0)