Skip to content

Commit 3e8c3b0

Browse files
authored
Revert "PERF: ArrowExtensionArray.to_numpy(dtype=object)" (#51273)
Revert "PERF: ArrowExtensionArray.to_numpy(dtype=object) (#51227)" This reverts commit 7ffc0ad.
1 parent 5be45c2 commit 3e8c3b0

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

doc/source/whatsnew/v2.0.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ Performance improvements
10781078
- Performance improvement in :meth:`~arrays.ArrowExtensionArray.factorize` (:issue:`49177`)
10791079
- Performance improvement in :meth:`~arrays.ArrowExtensionArray.__setitem__` (:issue:`50248`, :issue:`50632`)
10801080
- Performance improvement in :class:`~arrays.ArrowExtensionArray` comparison methods when array contains NA (:issue:`50524`)
1081-
- Performance improvement in :meth:`~arrays.ArrowExtensionArray.to_numpy` (:issue:`49973`, :issue:`51227`)
1081+
- Performance improvement in :meth:`~arrays.ArrowExtensionArray.to_numpy` (:issue:`49973`)
10821082
- Performance improvement when parsing strings to :class:`BooleanDtype` (:issue:`50613`)
10831083
- Performance improvement in :meth:`DataFrame.join` when joining on a subset of a :class:`MultiIndex` (:issue:`48611`)
10841084
- Performance improvement for :meth:`MultiIndex.intersection` (:issue:`48604`)

pandas/core/arrays/arrow/array.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -853,12 +853,12 @@ def to_numpy(
853853
na_value = self.dtype.na_value
854854

855855
pa_type = self._data.type
856-
if pa.types.is_timestamp(pa_type) or pa.types.is_duration(pa_type):
856+
if (
857+
is_object_dtype(dtype)
858+
or pa.types.is_timestamp(pa_type)
859+
or pa.types.is_duration(pa_type)
860+
):
857861
result = np.array(list(self), dtype=dtype)
858-
elif is_object_dtype(dtype) and self._hasna:
859-
result = np.empty(len(self), dtype=object)
860-
mask = ~self.isna()
861-
result[mask] = np.asarray(self[mask]._data)
862862
else:
863863
result = np.asarray(self._data, dtype=dtype)
864864
if copy or self._hasna:

pandas/tests/extension/test_arrow.py

-10
Original file line numberDiff line numberDiff line change
@@ -1518,16 +1518,6 @@ def test_to_numpy_with_defaults(data):
15181518
tm.assert_numpy_array_equal(result, expected)
15191519

15201520

1521-
def test_to_numpy_int_with_na():
1522-
# GH51227: ensure to_numpy does not convert int to float
1523-
data = [1, None]
1524-
arr = pd.array(data, dtype="int64[pyarrow]")
1525-
result = arr.to_numpy()
1526-
expected = np.array([1, pd.NA], dtype=object)
1527-
assert isinstance(result[0], int)
1528-
tm.assert_numpy_array_equal(result, expected)
1529-
1530-
15311521
def test_setitem_null_slice(data):
15321522
# GH50248
15331523
orig = data.copy()

0 commit comments

Comments
 (0)