-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: df[col] = arr should not overwrite data in df[col] #35417
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
150 commits
Select commit
Hold shift + click to select a range
a1ce4fc
Make df[col] insert a new array, never overwrite
jbrockmendel b1913b7
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel e600237
whatsnew
TomAugspurger 140f5f2
update tests
jbrockmendel c096c5d
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel cbd45e8
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 989ba97
update whatsnew
jbrockmendel bf6e5f5
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel a5ffd10
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel e126ab5
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 8c4f9f3
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel f716904
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 59e447a
Update merge test
jbrockmendel 09e89ee
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 11b8093
Fix cython groubpy.apply func for funcs that mutate inplace
jbrockmendel 4271303
cleanup commented-out
jbrockmendel ed0af51
mypy fixup
jbrockmendel dffae7e
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel a7f363b
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 53992df
Test for #35731
jbrockmendel 0a133d7
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel db1b668
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 858d6cb
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 3deb0a7
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 68e8715
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 3a74222
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel b0896be
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel f9498a3
revert accidental
jbrockmendel d81a696
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 33ef890
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel ea49ae2
move whatsnew note
jbrockmendel 1a850c8
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel fed4782
update version ref
jbrockmendel 0633cc6
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel a00702a
restore
jbrockmendel 1dd58ab
split_path compat
jbrockmendel 4ffe7f4
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 247d0f8
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 9164c83
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 080c7e9
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel b47ed01
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 0290975
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 13b683d
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 7e9ea2d
lint fixup
jbrockmendel bd55d67
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel ae9c707
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 4dd24ca
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 253f625
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 0b28fc0
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 9c5e6fa
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 2e0bf61
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 04af8fa
doc fixup, split tests
jbrockmendel 1d2b6d7
update test expected
jbrockmendel 65d466b
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 13077e9
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel f013ec3
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 66d5ed0
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel f23245b
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 23e9462
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 6c8b15f
fix broken test
jbrockmendel 03b3015
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 687d262
troubleshoot 32bit builds
jbrockmendel 9164a1e
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 02585c5
move whatsnew
jbrockmendel 3731fc8
restore 1.2.0 whatnsew
jbrockmendel 184f013
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 8503671
troubleshoot
jbrockmendel 34a96f7
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel a82f62b
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel fe58441
troubleshoot
jbrockmendel 28e6296
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 1e802b8
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel c1ab90f
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 382def7
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 4023a16
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 1e60537
flesh out tests
jbrockmendel 072ef99
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 51fe3b2
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 7edd45a
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 9783bce
arraymanager mypy fixup
jbrockmendel df6110e
Merge branch 'master' into 33457
jbrockmendel d7257f2
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 1f9f9c3
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 36fb2d4
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 1292a92
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 9b127bf
Merge branch 'master' into 33457
jbrockmendel 831dc71
Merge branch 'master' into 33457
jbrockmendel 1d50325
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel d72f379
Merge branch 'master' of https://github.com/pandas-dev/pandas into 33457
jbrockmendel 81e92d8
Merge branch 'master' into 33457
jbrockmendel 67435f8
simplify test
jbrockmendel ab833aa
Merge branch 'master' into 33457
jbrockmendel 017501e
Merge branch 'master' into 33457
jbrockmendel 0219f7f
Merge branch 'master' into 33457
jbrockmendel 032a55a
Merge branch 'master' into 33457
jbrockmendel 51d102b
un-xfail
jbrockmendel bd6816b
Merge branch 'master' into 33457
jbrockmendel 908b57b
Merge branch 'master' into 33457
jbrockmendel 62f2437
32bit compat
jbrockmendel 36b3302
troublehsoot
jbrockmendel 37c9d22
troubleshoot 32bit builds
jbrockmendel 0862ece
Merge branch 'master' into 33457
jbrockmendel 38d8106
troubleshoot 32 bit
jbrockmendel 647a393
DOC: suppress warnings from CategoricalBlock deprecation
jbrockmendel 8b8d6a2
Merge branch 'master' into ci-doc
jbrockmendel 9c6e008
Merge branch 'ci-doc' into 33457
jbrockmendel 8285ece
troubleshoot 32 bit builds
jbrockmendel 270be1e
troubleshoot 32bit builds
jbrockmendel 9cf69c9
typo fixup
jbrockmendel 065869a
Merge branch 'master' into 33457
jbrockmendel ca260c5
32bit troubleshoot
jbrockmendel 5dcdc4a
Merge branch 'master' into 33457
jbrockmendel a03dcc3
Merge branch 'master' into 33457
jbrockmendel a1c5732
revert troubleshoot
jbrockmendel 47b841a
Merge branch 'master' into 33457
jbrockmendel df060a5
Merge branch 'master' into 33457
jbrockmendel 017b817
Merge branch 'master' into 33457
jbrockmendel 0821a60
update test
jbrockmendel 608fb9d
Merge branch 'master' into 33457
jbrockmendel a70fcc2
Merge branch 'master' into 33457
jbrockmendel effd630
Merge branch 'master' into 33457
jbrockmendel 4e30881
Merge branch 'master' into 33457
jbrockmendel a254ed0
Merge branch 'master' into 33457
jbrockmendel df7b4d3
Merge branch 'master' into 33457
jbrockmendel 8f49c7f
Merge branch 'master' into 33457
jbrockmendel a66afa0
revert duplicated whatsnew notes
jbrockmendel fb95732
revert unrelated test fix
jbrockmendel c0bace5
Merge branch 'master' into 33457
jbrockmendel 9e43fe9
Merge branch 'master' into 33457
jbrockmendel f47fa2e
Merge branch 'master' into 33457
jbrockmendel 29d3bba
Merge branch 'master' into 33457
jbrockmendel 5b8de9a
Merge branch 'master' into 33457
jbrockmendel 79c7ae2
Merge branch 'master' into 33457
jbrockmendel fa2dcea
Merge branch 'master' into 33457
jbrockmendel 0e8f671
Merge branch 'master' into 33457
jbrockmendel 3cdeeb4
Merge branch 'master' into 33457
jbrockmendel acd3514
Merge branch 'master' into 33457
jbrockmendel d97a1ac
Merge branch 'master' into 33457
jbrockmendel 4342f5d
ArrayManager fixup
jbrockmendel f4dafc6
Merge branch 'master' into 33457
jbrockmendel bebb12f
avoid warning
jbrockmendel 04475e3
Merge branch 'master' into 33457
jbrockmendel ed6f3ec
Merge branch 'master' into 33457
jbrockmendel fe9fe66
fixed on AM
jbrockmendel 1ae50bf
Merge branch 'master' into 33457
jbrockmendel 9d32c62
Merge branch 'master' into 33457
jbrockmendel 8972875
Merge branch 'master' into 33457
jbrockmendel 6524331
revert whitespace change
jbrockmendel 123568d
revert no-longer-necessary
jbrockmendel 8bef37a
Merge branch 'master' into 33457
jbrockmendel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -642,33 +642,31 @@ def test_get_numeric_data(self): | |
item_shape=(3,), | ||
) | ||
mgr.iset(5, np.array([1, 2, 3], dtype=np.object_)) | ||
|
||
numeric = mgr.get_numeric_data() | ||
tm.assert_index_equal( | ||
numeric.items, pd.Index(["int", "float", "complex", "bool"]) | ||
) | ||
mgr_idx = mgr.items.get_loc("float") | ||
num_idx = numeric.items.get_loc("float") | ||
|
||
tm.assert_almost_equal( | ||
mgr.iget(mgr.items.get_loc("float")).internal_values(), | ||
numeric.iget(numeric.items.get_loc("float")).internal_values(), | ||
mgr.iget(mgr_idx).internal_values(), | ||
numeric.iget(num_idx).internal_values(), | ||
) | ||
|
||
# Check sharing | ||
numeric.iset(numeric.items.get_loc("float"), np.array([100.0, 200.0, 300.0])) | ||
numeric.iget(num_idx).internal_values()[:] = [100.0, 200.0, 300.0] | ||
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. i would split the inplace to a separate test |
||
tm.assert_almost_equal( | ||
mgr.iget(mgr.items.get_loc("float")).internal_values(), | ||
np.array([100.0, 200.0, 300.0]), | ||
mgr.iget(mgr_idx).internal_values(), np.array([100.0, 200.0, 300.0]), | ||
) | ||
|
||
numeric2 = mgr.get_numeric_data(copy=True) | ||
tm.assert_index_equal( | ||
numeric.items, pd.Index(["int", "float", "complex", "bool"]) | ||
) | ||
numeric2.iset( | ||
numeric2.items.get_loc("float"), np.array([1000.0, 2000.0, 3000.0]) | ||
) | ||
numeric2.iget(num_idx).internal_values()[:] = [1000.0, 2000.0, 3000.0] | ||
tm.assert_almost_equal( | ||
mgr.iget(mgr.items.get_loc("float")).internal_values(), | ||
np.array([100.0, 200.0, 300.0]), | ||
mgr.iget(mgr_idx).internal_values(), np.array([100.0, 200.0, 300.0]), | ||
) | ||
|
||
def test_get_bool_data(self): | ||
|
@@ -686,18 +684,20 @@ def test_get_bool_data(self): | |
bools.iget(bools.items.get_loc("bool")).internal_values(), | ||
) | ||
|
||
# GH#33457 setting a new array on bools does _not_ alter the original | ||
# array in-place, so mgr is unchanged | ||
bools.iset(0, np.array([True, False, True])) | ||
tm.assert_numpy_array_equal( | ||
mgr.iget(mgr.items.get_loc("bool")).internal_values(), | ||
np.array([True, False, True]), | ||
np.array([True, True, True]), | ||
) | ||
|
||
# Check sharing | ||
# Check non-sharing | ||
bools2 = mgr.get_bool_data(copy=True) | ||
bools2.iset(0, np.array([False, True, False])) | ||
bools2.blocks[0].values[:] = [[False, True, False]] | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tm.assert_numpy_array_equal( | ||
mgr.iget(mgr.items.get_loc("bool")).internal_values(), | ||
np.array([True, False, True]), | ||
np.array([True, True, True]), | ||
) | ||
|
||
def test_unicode_repr_doesnt_raise(self): | ||
|
@@ -1181,23 +1181,6 @@ def test_binop_other(self, op, value, dtype): | |
tm.assert_series_equal(result, expected) | ||
|
||
|
||
class TestShouldStore: | ||
def test_should_store_categorical(self): | ||
cat = pd.Categorical(["A", "B", "C"]) | ||
df = pd.DataFrame(cat) | ||
blk = df._mgr.blocks[0] | ||
|
||
# matching dtype | ||
assert blk.should_store(cat) | ||
assert blk.should_store(cat[:-1]) | ||
|
||
# different dtype | ||
assert not blk.should_store(cat.as_ordered()) | ||
|
||
# ndarray instead of Categorical | ||
assert not blk.should_store(np.asarray(cat)) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"typestr, holder", | ||
[ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.