Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
Rows arrive as strings and a spec says what each field should be. One unparseable value in a million-row batch should cost you that row — not the batch, and not silently.
Write parse_fields(rows, spec). It returns the rows that converted cleanly and an error record for every field that did not.
Function to write
parse_fields(rows: list[dict], spec: dict) -> dictA dict with the cleanly-`parsed` rows and one error record per failing field.
How to approach it
Decide what an error record must contain before you write the conversion.
Sample cases
+ 2 held back until you submit
a row that parses cleanly
The ordinary case: three fields converted, no errors, and the amount kept exact.
Input
Argument 1
| id | amount | at |
|---|---|---|
| 1042 | 12.50 | 2026-09-01 |
Argument 2
{
'id': 'int',
'amount': 'amount',
'at': 'date'
}Returns
{
'parsed': [
{
'amount': '12.50',
'at': '2026-09-01',
'id': 1042
}
],
'errors': []
}a row where every field is wrong
Three separate errors from one row, each naming its own field — not one error for the row.
Input
Argument 1
| id | amount | at |
|---|---|---|
| x | 12,5 | 2026-13-01 |
Argument 2
{
'id': 'int',
'amount': 'amount',
'at': 'date'
}Returns
{
'parsed': [],
'errors': [
{
'row': 0,
'field': 'amount',
'value': '12,5',
'reason': 'not a valid amount',
'cause': 'InvalidOperation'
},
{
'row': 0,
'field': 'at',
'value': '2026-13-01',
'reason': 'not a valid date',
'cause': 'ValueError'
},
{
'row': 0,
'field': 'id',
'value': 'x',
'reason': 'not a valid int',
'cause': 'ValueError'
}
]
}no rows
An empty batch parses to empty lists rather than raising anywhere.
Input
Argument 1
[] (empty list)
Argument 2
{
'id': 'int',
'amount': 'amount',
'at': 'date'
}Returns
{
'parsed': [],
'errors': []
}Constraints
{'parsed': [...], 'errors': [...]}.int, amount, date and anything else means text. Amounts are converted with Decimal and returned as strings so the digits survive; dates are returned in ISO form.None or blank value is a failure, not a zero and not an empty string.{'row': <index>, 'field': ..., 'value': <the raw value>, 'reason': ..., 'cause': <the exception class name>}.parsed. Other rows are unaffected.Worked example
A row arrives with id of x, amount of 12,5 and at of 2026-13-01.
All three fail, and each produces its own error naming its own field — not one error for the row saying it was bad. That difference is the whole exercise: amount failing with a comma tells somebody the producer changed locale, and a row-level error tells them nothing at all.
What this tests
That failure is data. An exception loses the batch and a silent default loses the evidence; a report with the field, the offending value and the reason is what lets somebody fix the source rather than guess at it.
parse_fields(rows: list[dict], spec: dict) -> dictSubmit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.