Skip to main content
Back to Python Coding

Python Coding · Doing It With AI

Spot the Bug AI Python

Spot the Bug: AI-Generated Python

The one idea: AI-written pandas runs cleanly and fails in the same three places every time: averaging a rate the wrong way, a merge that silently drops rows, and misreading what a missing value meant. You don't need to write the fix — you run a few cheap checks that force whoever wrote the code to correct it.
⚠️ The trap: fillna(0) is a harmless cleanup step that just tidies up the blanks. That feels right and it's wrong. Where a blank (NaN, pandas' missing-value marker) means "never happened" — a lead that never converted — filling it with 0 invents instant conversions and drags the average toward zero, and .mean() already skips blanks on its own, so the "cleanup" is the entire bug.

An AI can produce a pandas analysis in seconds that loads, runs, and prints confident numbers — and still be quietly wrong in a way that flips the business decision. Your job isn't to write the fix. It's to run the checks that expose the bug, then hand it back with the one question that forces the correction.

Why AI-generated pandas fails in specific, predictable ways

AI models are excellent at producing runnable pandas and good at common patterns, but they don't execute the code against your actual data before showing it to you, and they fill unspecified details with plausible defaults. That means the traps from earlier lessons — merge row-count changes, aggregation order, what NaN meant in your data — show up in AI output at least as often as in human-written code, delivered with more confident phrasing ("Here's the conversion rate by channel..."). The…

Keep reading: Spot the Bug AI Python

Sign up free to read the full lesson, ask the AI tutor, and take practice questions.

  • Full lesson content
  • AI tutor for this section
  • Practice questions