-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
API / CoW: always return new objects for column access (don't use item_cache) #49450
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 1 commit
57cf2e7
32fa0a4
565f36b
5078914
cea5fcb
d4e9b7e
8da630c
4d13648
55b3785
3e79282
1db5a6f
92cfa34
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 |
---|---|---|
|
@@ -620,6 +620,34 @@ def test_column_as_series_set_with_upcast(using_copy_on_write, using_array_manag | |
tm.assert_frame_equal(df, df_orig) | ||
|
||
|
||
def test_column_as_series_no_item_cache(using_copy_on_write, using_array_manager): | ||
# Case: selecting a single column (which now also uses Copy-on-Write to protect | ||
# the view) should always give a new object (i.e. not make use of a cache) | ||
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [0.1, 0.2, 0.3]}) | ||
df_orig = df.copy() | ||
|
||
s1 = df["a"] | ||
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. Is it worth testing the other indexing methods that will return a columns as a Series (loc/iloc)? 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. Good call, |
||
s2 = df["a"] | ||
|
||
if using_copy_on_write: | ||
assert s1 is not s2 | ||
else: | ||
assert s1 is s2 | ||
|
||
if using_copy_on_write or using_array_manager: | ||
s1.iloc[0] = 0 | ||
else: | ||
with pd.option_context("chained_assignment", "warn"): | ||
with tm.assert_produces_warning(SettingWithCopyWarning): | ||
s1.iloc[0] = 0 | ||
|
||
if using_copy_on_write: | ||
tm.assert_series_equal(s2, df_orig["a"]) | ||
tm.assert_series_equal(df["a"], df_orig["a"]) | ||
else: | ||
assert s2.iloc[0] == 0 | ||
|
||
|
||
# TODO add tests for other indexing methods on the Series | ||
|
||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.