MCPcopy
hub / github.com/pandas-dev/pandas / test_subset_row_slice

Function test_subset_row_slice

pandas/tests/copy_view/test_indexing.py:95–116  ·  view source on GitHub ↗
(backend)

Source from the content-addressed store, hash-verified

93
94
95def test_subset_row_slice(backend):
96 # Case: taking a subset of the rows of a DataFrame using a slice
97 # + afterwards modifying the subset
98 _, DataFrame, _ = backend
99 df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [0.1, 0.2, 0.3]})
100 df_orig = df.copy()
101
102 subset = df[1:3]
103 subset._mgr._verify_integrity()
104
105 assert subset.columns is not df.columns
106 assert np.shares_memory(get_array(subset, "a"), get_array(df, "a"))
107
108 subset.iloc[0, 0] = 0
109 assert not np.shares_memory(get_array(subset, "a"), get_array(df, "a"))
110
111 subset._mgr._verify_integrity()
112
113 expected = DataFrame({"a": [0, 3], "b": [5, 6], "c": [0.2, 0.3]}, index=range(1, 3))
114 tm.assert_frame_equal(subset, expected)
115 # original parent dataframe is not modified (CoW)
116 tm.assert_frame_equal(df, df_orig)
117
118
119@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 4

DataFrameClass · 0.90
get_arrayFunction · 0.90
copyMethod · 0.45
_verify_integrityMethod · 0.45

Tested by

no test coverage detected