-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
BUG: ensure we still honor copy=True in Series constructor in all cases #63342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -403,6 +403,7 @@ def __init__( | |
| if copy is not False: | ||
| if dtype is None or astype_is_view(data.dtype, pandas_dtype(dtype)): | ||
| data = data.copy() | ||
| copy = False | ||
| if copy is None: | ||
| copy = False | ||
|
|
||
|
|
@@ -417,6 +418,7 @@ def __init__( | |
| Pandas4Warning, | ||
| stacklevel=2, | ||
| ) | ||
| allow_mgr = True | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid raising this warning a second time below in some specific corner case |
||
|
|
||
| name = ibase.maybe_extract_name(name, data, type(self)) | ||
|
|
||
|
|
@@ -442,9 +444,8 @@ def __init__( | |
| if isinstance(data, Index): | ||
| if dtype is not None: | ||
| data = data.astype(dtype) | ||
|
|
||
| refs = data._references | ||
| copy = False | ||
| if not copy: | ||
mroeschke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| refs = data._references | ||
|
|
||
| elif isinstance(data, np.ndarray): | ||
| if len(data.dtype): | ||
|
|
@@ -460,8 +461,9 @@ def __init__( | |
| data = data._mgr.copy(deep=False) | ||
| else: | ||
| data = data.reindex(index) | ||
| copy = False | ||
| data = data._mgr | ||
| if data._has_no_reference(0): | ||
| copy = False | ||
|
Comment on lines
-463
to
+466
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reindex could in theory return a shallow copy instead of full copy (if the passed index is identical to That is to ensure that if the user specified |
||
| elif isinstance(data, Mapping): | ||
| data, index = self._init_dict(data, index, dtype) | ||
| dtype = None | ||
|
|
@@ -506,8 +508,10 @@ def __init__( | |
| # create/copy the manager | ||
| if isinstance(data, SingleBlockManager): | ||
| if dtype is not None: | ||
| if not astype_is_view(data.dtype, pandas_dtype(dtype)): | ||
| copy = False | ||
| data = data.astype(dtype=dtype) | ||
| elif copy: | ||
| if copy: | ||
| data = data.copy(deep=True) | ||
| else: | ||
| data = sanitize_array(data, index, dtype, copy) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid another copy later