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

Function test_subset_set_column

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

Source from the content-addressed store, hash-verified

285
286
287def test_subset_set_column(backend):
288 # Case: setting a single column on a viewing subset -> subset[col] = value
289 dtype_backend, DataFrame, _ = backend
290 df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [0.1, 0.2, 0.3]})
291 df_orig = df.copy()
292 subset = df[1:3]
293
294 if dtype_backend == "numpy":
295 arr = np.array([10, 11], dtype="int64")
296 else:
297 arr = pd.array([10, 11], dtype="Int64")
298
299 subset["a"] = arr
300 subset._mgr._verify_integrity()
301 expected = DataFrame(
302 {"a": [10, 11], "b": [5, 6], "c": [0.2, 0.3]}, index=range(1, 3)
303 )
304 tm.assert_frame_equal(subset, expected)
305 tm.assert_frame_equal(df, df_orig)
306
307
308@pytest.mark.parametrize(

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected