Skip to content

API / CoW: Copy NumPy arrays by default in DataFrame constructor #51731

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

Merged
merged 29 commits into from
Mar 17, 2023
Merged
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
563257e
Implement copy by default for numpy array
phofl Mar 1, 2023
f3161a3
Fix tests
phofl Mar 1, 2023
3a95311
Simplify
phofl Mar 2, 2023
17cf5ae
Fix
phofl Mar 2, 2023
07aa26d
Remove
phofl Mar 2, 2023
8e84d85
Merge branch 'main' into cow_copy_numpy_array
phofl Mar 2, 2023
f3ccf0f
Add comment
phofl Mar 3, 2023
5cdc6ad
Fix
phofl Mar 3, 2023
3e384ea
Change logic
phofl Mar 3, 2023
49ee53f
Merge remote-tracking branch 'upstream/main' into cow_copy_numpy_array
phofl Mar 3, 2023
fcc7be2
Fix tests
phofl Mar 3, 2023
9223836
Fix test
phofl Mar 3, 2023
a474bf5
Fix test
phofl Mar 3, 2023
d5a0268
Merge branch 'main' into cow_copy_numpy_array
phofl Mar 4, 2023
0be7fc6
Merge remote-tracking branch 'upstream/main' into cow_copy_numpy_array
phofl Mar 7, 2023
293f8a5
Remove order changes
phofl Mar 14, 2023
3376d06
Merge remote-tracking branch 'upstream/main' into cow_copy_numpy_array
phofl Mar 14, 2023
265d9e3
Update
phofl Mar 14, 2023
9ac1bae
Address review
phofl Mar 14, 2023
db92ce4
Add test
phofl Mar 14, 2023
be9cb04
Fix test
phofl Mar 15, 2023
4bf3ee8
Merge branch 'main' into cow_copy_numpy_array
phofl Mar 15, 2023
e2eceec
Fix array manager
phofl Mar 15, 2023
65965c6
Remove elif
phofl Mar 15, 2023
ecb756c
Update pandas/tests/copy_view/test_constructors.py
phofl Mar 15, 2023
8e837d9
Merge remote-tracking branch 'upstream/main' into cow_copy_numpy_array
phofl Mar 15, 2023
177fbbc
Add whatsnew
phofl Mar 15, 2023
2bbff3b
Merge branch 'main' into cow_copy_numpy_array
phofl Mar 16, 2023
5bef4ba
Add note
phofl Mar 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ Copy-on-Write improvements
of Series objects and specifying ``copy=False``, will now use a lazy copy
of those Series objects for the columns of the DataFrame (:issue:`50777`)

- The :class:`DataFrame` constructor, when constructing from a NumPy array,
will now copy the array by default to avoid mutating the :class:`DataFrame`
when mutating the array. Specify ``copy=False`` to get the old behavior.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a warning like (about copy=False): "in that case pandas does not guarantee correct Copy-on-Write behaviour in case the numpy array would get modified after creating the DataFrame"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added


- Trying to set values using chained assignment (for example, ``df["a"][1:3] = 0``)
will now always raise an warning when Copy-on-Write is enabled. In this mode,
chained assignment can never work because we are always setting into a temporary
Expand Down