Menu

pd.to_numeric(errors="coerce") Hid a $22.6M Bug in My Test Billing Feed
📰

pd.to_numeric(errors="coerce") Hid a $22.6M Bug in My Test Billing Feed

DEV Community: python·endlessfountain·3 days ago
#7YFTYZC5
#devtopython#devto#dev#reasons#rows
Reading 0:00
15s threshold

Whenever a nightly CSV import starts failing on dirty strings, somebody eventually opens a pull request with this one-liner:

python

df [ " amount " ] = pd . to_numeric ( df [ " amount_raw " ], errors = " coerce " ). fillna ( 0.0 )

Enter fullscreen mode

Exit fullscreen mode

I get why people write it. When you have 500,000 payment events waiting to load and row 41,209 contains "$1,299.00" instead of "1299.00", letting float() blow up the whole job at 3:00 AM feels worse than coercing bad strings to NaN.

Except errors="coerce" doesn't just skip broken rows. Paired with .fillna(0.0), it turns formatted enterprise invoices into zero-dollar charges without logging a single warning.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.