Complete worked example
python
import pandas as pd
def inspect_example(values):
frame = pd.DataFrame({"score": pd.array(values, dtype="Float64")})
preview = frame["score"]
before = preview.copy()
mask = frame["score"].isna()
frame.loc[mask, "score"] = 0
pd.testing.assert_series_equal(preview, before)
return frame- Reasoning
- Select the score Series and keep it as preview. Build a missing-score mask and assign zero into the owning frame with frame.loc[mask, "score"]. The preview still represents the pre-update values under Copy-on-Write. An explicit assertion makes that behavior observable. Return the changed frame with the same nullable schema and row order. Trace a missing score followed by a score of five. The result is zero and five, while preview still begins with a missing value. Reading a column is not an instruction to link later writes to its parent. State which object each assignment is supposed to change.