File tree Expand file tree Collapse file tree 4 files changed +8
-48
lines changed
Expand file tree Collapse file tree 4 files changed +8
-48
lines changed Original file line number Diff line number Diff line change 3737)
3838from pandas .util ._exceptions import find_stack_level
3939
40- from pandas .core .dtypes .astype import astype_is_view
4140from pandas .core .dtypes .common import (
4241 is_scalar ,
43- pandas_dtype ,
4442)
4543from pandas .core .dtypes .dtypes import (
4644 ArrowDtype ,
4947from pandas .core .dtypes .generic import ABCSeries
5048from pandas .core .dtypes .missing import is_valid_na_for_dtype
5149
52- from pandas .core .arrays import ExtensionArray
5350from pandas .core .arrays .datetimes import (
5451 DatetimeArray ,
5552 tz_to_dtype ,
@@ -689,15 +686,8 @@ def __new__(
689686
690687 name = maybe_extract_name (name , data , cls )
691688
692- if isinstance (data , (ExtensionArray , np .ndarray )):
693- # GH 63388
694- if copy is not False :
695- if dtype is None or astype_is_view (
696- data .dtype ,
697- pandas_dtype (dtype ),
698- ):
699- data = data .copy ()
700- copy = False
689+ # GH#63388
690+ data , copy = cls ._maybe_copy_input (data , copy , dtype )
701691
702692 if (
703693 isinstance (data , DatetimeArray )
Original file line number Diff line number Diff line change 3535)
3636from pandas .util ._exceptions import rewrite_exception
3737
38- from pandas .core .dtypes .astype import astype_is_view
3938from pandas .core .dtypes .cast import (
4039 find_common_type ,
4140 infer_dtype_from_scalar ,
6261from pandas .core .dtypes .missing import is_valid_na_for_dtype
6362
6463from pandas .core .algorithms import unique
65- from pandas .core .arrays import ExtensionArray
6664from pandas .core .arrays .datetimelike import validate_periods
6765from pandas .core .arrays .interval import (
6866 IntervalArray ,
@@ -265,15 +263,8 @@ def __new__(
265263 ) -> Self :
266264 name = maybe_extract_name (name , data , cls )
267265
268- if isinstance (data , (ExtensionArray , np .ndarray )):
269- # GH#63388
270- if copy is not False :
271- if dtype is None or astype_is_view (
272- data .dtype ,
273- pandas_dtype (dtype ),
274- ):
275- data = data .copy ()
276- copy = False
266+ # GH#63388
267+ data , copy = cls ._maybe_copy_input (data , copy , dtype )
277268
278269 with rewrite_exception ("IntervalArray" , cls .__name__ ):
279270 array = IntervalArray (
Original file line number Diff line number Diff line change 2727 set_module ,
2828)
2929
30- from pandas .core .dtypes .astype import astype_is_view
3130from pandas .core .dtypes .common import (
3231 is_integer ,
33- pandas_dtype ,
3432)
3533from pandas .core .dtypes .dtypes import PeriodDtype
3634from pandas .core .dtypes .generic import ABCSeries
3735from pandas .core .dtypes .missing import is_valid_na_for_dtype
3836
39- from pandas .core .arrays import ExtensionArray
4037from pandas .core .arrays .period import (
4138 PeriodArray ,
4239 period_array ,
@@ -241,15 +238,8 @@ def __new__(
241238
242239 freq = validate_dtype_freq (dtype , freq )
243240
244- if isinstance (data , (ExtensionArray , np .ndarray )):
245- # GH 63388
246- if copy is not False :
247- if dtype is None or astype_is_view (
248- data .dtype ,
249- pandas_dtype (dtype ),
250- ):
251- data = data .copy ()
252- copy = False
241+ # GH#63388
242+ data , copy = cls ._maybe_copy_input (data , copy , dtype )
253243
254244 # PeriodIndex allow PeriodIndex(period_index, freq=different)
255245 # Let's not encourage that kind of behavior in PeriodArray.
Original file line number Diff line number Diff line change 77 cast ,
88)
99
10- import numpy as np
11-
1210from pandas ._libs import (
1311 index as libindex ,
1412 lib ,
2119from pandas ._libs .tslibs .dtypes import abbrev_to_npy_unit
2220from pandas .util ._decorators import set_module
2321
24- from pandas .core .dtypes .astype import astype_is_view
2522from pandas .core .dtypes .common import (
2623 is_scalar ,
2724 pandas_dtype ,
2825)
2926from pandas .core .dtypes .dtypes import ArrowDtype
3027from pandas .core .dtypes .generic import ABCSeries
3128
32- from pandas .core .arrays import ExtensionArray
3329from pandas .core .arrays .timedeltas import TimedeltaArray
3430import pandas .core .common as com
3531from pandas .core .indexes .base import (
@@ -172,15 +168,8 @@ def __new__(
172168 ):
173169 name = maybe_extract_name (name , data , cls )
174170
175- if isinstance (data , (ExtensionArray , np .ndarray )):
176- # GH 63388
177- if copy is not False :
178- if dtype is None or astype_is_view (
179- data .dtype ,
180- pandas_dtype (dtype ),
181- ):
182- data = data .copy ()
183- copy = False
171+ # GH#63388
172+ data , copy = cls ._maybe_copy_input (data , copy , dtype )
184173
185174 if is_scalar (data ):
186175 cls ._raise_scalar_data_error (data )
You can’t perform that action at this time.
0 commit comments