Skip to content

Commit 421f904

Browse files
fix copy=False case for masked array
1 parent 3b000be commit 421f904

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pandas/core/arrays/masked.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def to_numpy(
507507
else:
508508
with warnings.catch_warnings():
509509
warnings.filterwarnings("ignore", category=RuntimeWarning)
510-
data = np.array(self._data, dtype=dtype, copy=copy)
510+
data = self._data.astype(dtype, copy=copy)
511511
return data
512512

513513
@doc(ExtensionArray.tolist)
@@ -581,7 +581,10 @@ def __array__(
581581
the array interface, return my values
582582
We return an object array here to preserve our scalar values
583583
"""
584-
if copy is False and self._hasna:
584+
if copy is False:
585+
if not self._hasna:
586+
# special case, here we can simply return the underlying data
587+
return np.array(self._data, dtype=dtype, copy=copy)
585588
raise ValueError(
586589
"Unable to avoid copy while creating an array as requested."
587590
)

0 commit comments

Comments
 (0)