File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed
Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff 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" :
Original file line number Diff line number Diff line change 55 DataFrame ,
66 Index ,
77 Series ,
8+ array ,
89)
910import pandas ._testing as tm
1011from 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+
161168def test_series_from_temporary_index_readonly_data ():
162169 # GH 63370
163170 arr = np .array ([0 , 1 ], dtype = np .dtype (np .int8 ))
You can’t perform that action at this time.
0 commit comments