Skip to content

Commit 974bc2a

Browse files
committed
Move check up, add test for EA
1 parent 435cbf1 commit 974bc2a

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

pandas/core/indexes/base.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,13 @@ def __new__(
499499
if not copy and isinstance(data, (ABCSeries, Index)):
500500
refs = data._references
501501

502+
if isinstance(data, (ExtensionArray, np.ndarray)):
503+
# GH 63306
504+
if copy is not False:
505+
if dtype is None or astype_is_view(data.dtype, dtype):
506+
data = data.copy()
507+
copy = False
508+
502509
# range
503510
if isinstance(data, (range, RangeIndex)):
504511
result = RangeIndex(start=data, copy=bool(copy), name=name)
@@ -517,13 +524,7 @@ def __new__(
517524
pass
518525

519526
elif isinstance(data, (np.ndarray, ABCMultiIndex)):
520-
if isinstance(data, np.ndarray):
521-
if copy is not False:
522-
if dtype is None or astype_is_view(data.dtype, pandas_dtype(dtype)):
523-
# GH 63306
524-
data = data.copy()
525-
copy = False
526-
elif isinstance(data, ABCMultiIndex):
527+
if isinstance(data, ABCMultiIndex):
527528
data = data._values
528529

529530
if data.dtype.kind not in "iufcbmM":

pandas/tests/copy_view/index/test_index.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
DataFrame,
66
Index,
77
Series,
8+
array,
89
)
910
import pandas._testing as tm
1011
from pandas.tests.copy_view.util import get_array
@@ -158,6 +159,12 @@ def test_constructor_copy_input_ndarray_default():
158159
assert not np.shares_memory(arr, get_array(idx))
159160

160161

162+
def test_constructor_copy_input_ea_default():
163+
arr = array([0, 1], dtype="Int64")
164+
idx = Index(arr)
165+
assert not tm.shares_memory(arr, idx.array)
166+
167+
161168
def test_series_from_temporary_index_readonly_data():
162169
# GH 63370
163170
arr = np.array([0, 1], dtype=np.dtype(np.int8))

0 commit comments

Comments
 (0)