Skip to content

Commit 4adbea1

Browse files
committed
CLN: rollback unittest unralted to _item_cache
1 parent 81788a6 commit 4adbea1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/copy_view/test_indexing.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,33 @@ def test_column_as_series_set_with_upcast(backend):
734734
s[0] = "foo"
735735

736736

737+
@pytest.mark.parametrize(
738+
"method",
739+
[
740+
lambda df: df["a"],
741+
lambda df: df.loc[:, "a"],
742+
lambda df: df.iloc[:, 0],
743+
],
744+
ids=["getitem", "loc", "iloc"],
745+
)
746+
def test_column_as_series_no_item_cache(request, backend, method):
747+
# Case: selecting a single column (which now also uses Copy-on-Write to protect
748+
# the view) should always give a new object (i.e. not make use of a cache)
749+
dtype_backend, DataFrame, _ = backend
750+
df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [0.1, 0.2, 0.3]})
751+
df_orig = df.copy()
752+
753+
s1 = method(df)
754+
s2 = method(df)
755+
756+
assert s1 is not s2
757+
758+
s1.iloc[0] = 0
759+
760+
tm.assert_series_equal(s2, df_orig["a"])
761+
tm.assert_frame_equal(df, df_orig)
762+
763+
737764
# TODO add tests for other indexing methods on the Series
738765

739766

0 commit comments

Comments
 (0)