THE INVESTIGATION
The group that loses null
Grouping keeps a missing-value group, but asking how many groups exist fails.
DataMissing valuesContracts
What’s going wrong
A grouping utility can retain missing keys, but its length operation still applies a category restriction that does not belong to group counting.
Input is {"keys": [...], "dropna": boolean}, where each key is a string or null. Print the number of distinct groups. Strings match exactly. If dropna is true, ignore null; if false, every null belongs to one additional group. The empty input has zero groups. Repair count_groups so counting does not reconstruct an unrelated representation.
Expected behavior
Count actual groups, including the missing-value group exactly when requested.
Reproduction
01 Retained null group
{"keys":["foo","bar",null],"dropna":false}3
02 Ordinary distinct groups
{"keys":["a","b","a"],"dropna":false}2
03 Drop null deliberately
{"keys":["a",null,null],"dropna":true}1
Before you begin
- Dictionaries
- Missing values
- Distinct values
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
Ready when you are
Every fix starts with a failing test.
Read the report, then sign in to start your investigation.