---
# System prepended metadata

title: Copy-on-Write warning mode

---

This describes a potential approach to warn in scenarios where Copy-on-Write will change the behavior.

# Approach

The warnings will be very noisy and users probably won't care about them 95% of the time. So we will hide the warnings behind a configuration that is explicit opt-in

# How to identify cases where to warn

Generally, we don't want to raise warnings when we do a lazy copy or something similar under CoW. This is an implementation detail.

We only want to warn when previous versions of pandas would have updated two objects at once or when ChainedAssignment is attempted.

The second one is pretty easy since we can use the same mechanism that we also use for detecting chained assignment under CoW.

The first case is relatively difficult. One possible approach would be to add another reference tracking mode that tracks references when the current default implementation returns a view, e.g. in some indexing operations or when ``copy=False`` is set explicitly. Basically the same as what CoW does, but in the default mode. 

This would enable us to raise warnings when values are set into an object that shares data with another DataFrame. This is the same approach as right now when we copy the data when a reference exists. The implementation would increase internal complexity though. We could potentially merge this shortly before 2.2 is released and then immediately rip it out again to keep the strain on main as small as possible. 