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

Function test_subset_column_slice

pandas/tests/copy_view/test_indexing.py:122–144  ·  view source on GitHub ↗
(backend, dtype)

Source from the content-addressed store, hash-verified

120 "dtype", ["int64", "float64"], ids=["single-block", "mixed-block"]
121)
122def test_subset_column_slice(backend, dtype):
123 # Case: taking a subset of the columns of a DataFrame using a slice
124 # + afterwards modifying the subset
125 dtype_backend, DataFrame, _ = backend
126 df = DataFrame(
127 {"a": [1, 2, 3], "b": [4, 5, 6], "c": np.array([7, 8, 9], dtype=dtype)}
128 )
129 df_orig = df.copy()
130
131 subset = df.iloc[:, 1:]
132 subset._mgr._verify_integrity()
133
134 assert subset.index is not df.index
135 assert np.shares_memory(get_array(subset, "b"), get_array(df, "b"))
136
137 subset.iloc[0, 0] = 0
138 assert not np.shares_memory(get_array(subset, "b"), get_array(df, "b"))
139
140 expected = DataFrame({"b": [0, 5, 6], "c": np.array([7, 8, 9], dtype=dtype)})
141 tm.assert_frame_equal(subset, expected)
142 # original parent dataframe is not modified (also not for BlockManager case,
143 # except for single block)
144 tm.assert_frame_equal(df, df_orig)
145
146
147@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected