-
-
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -265,8 +265,12 @@ class Series(base.IndexOpsMixin, NDFrame): # type: ignore[misc] | |
| See the :ref:`user guide <basics.dtypes>` for more usages. | ||
| name : Hashable, default None | ||
| The name to give to the Series. | ||
| copy : bool, default False | ||
| Copy input data. Only affects Series or 1d ndarray input. See examples. | ||
| copy : bool, default None | ||
| Copy input data. By default, will copy if the input data is a numpy or | ||
| pandas array. | ||
| Set to False to avoid copying, at your own risk (if you know the input | ||
| data won't be modified elsewhere). | ||
| Only affects Series or 1d ndarray input. See examples. | ||
|
|
||
| See Also | ||
| -------- | ||
|
|
@@ -397,6 +401,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 | ||
|
|
||
|
|
@@ -411,6 +416,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)) | ||
|
|
||
|
|
@@ -436,9 +442,8 @@ def __init__( | |
| if isinstance(data, Index): | ||
| if dtype is not None: | ||
| data = data.astype(dtype) | ||
|
|
||
| refs = data._references | ||
| copy = False | ||
| if not copy: | ||
|
Member
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. Just confirming, does this impact the behavior/address #63306?
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. No, because the default for Index input is |
||
| refs = data._references | ||
|
|
||
| elif isinstance(data, np.ndarray): | ||
| if len(data.dtype): | ||
|
|
@@ -454,8 +459,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
-457
to
+464
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 | ||
|
|
@@ -500,8 +506,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