The cleaning script
had run every night
for years.

Negative quantities
became zero.

Missing prices
became zero.

df[df["qty"] < 0]["qty"] = 0
df["price"].fillna(0, inplace=True)

Two lines.

Short.

Familiar.

And both of them
depend on something
pandas never promised.

The first one
was already broken.

The filter makes a copy,
the zero goes into the copy,
and the copy is thrown away.

That is where the old
SettingWithCopyWarning
came from,
the one everybody learned
to ignore.

The second one
often worked,
because the column
you got back
happened to share memory
with the frame.

Here is what changes.

pandas 3.0
makes Copy on Write
the default,
and the only behaviour.

Every column you pull out,
every filtered frame,
behaves as its own copy.

Change it
and the original
stays exactly as it was.

So chained assignment
never updates the frame.

Not sometimes.

Never.

The same goes for
an inplace method
called on a column
you pulled out first.

pandas will warn you,
with a ChainedAssignmentError.

It is a warning,
not an exception.

The script still finishes.

The report still goes out.

Only now
the negatives are still negative
and the prices are still missing.

This is the shape
of where things are going.

Libraries are turning
accidental behaviour
into defined behaviour.

Usually the defined behaviour
is the one you meant.

But code that relied
on the accident
does not crash.

It just
stops doing its job.

What to do,
before you upgrade:

Write each update
in one step,
on the frame itself:

df.loc[df["qty"] < 0, "qty"] = 0
df["price"] = df["price"].fillna(0)

On pandas 2.2,
set this
and run your jobs:

pd.options.mode.copy_on_write = "warn"

It reports the places
where the new rules
will give a different answer.

Turn warnings into errors
in your tests,
so a warning
cannot scroll past.

And check the output,
not the exit code.

Count the negatives
after cleaning.

It should be zero.

An upgrade
that removes an accident
will always find someone
who was standing on it.

– Serguey Asael Shinder