A workout export contains duration in seconds. A dashboard wants minutes, and a later summary wants total training time. If minutes are calculated in an unnamed preprocessing step, the dashboard quietly depends on that step running first. Pandera 0.36 lets you put the derivation in the schema so the input, transformation and output check can be reviewed together.
Declare one source and one derived field
Here is a small pandas example adapted from the single-source ParsedField interface in the release documentation. The input is synthetic. Two sessions last 90 and 150 seconds. Their expected values in minutes are 1.5 and 2.5, which give a useful independent check on both the direction of conversion and the decision to preserve fractions.
import pandas as pd
import pandera.pandas as pa
class Sessions(pa.DataFrameModel):
seconds: int = pa.Field(ge=0)
minutes: float = pa.ParsedField(
source="seconds", parser=lambda s: s / 60, ge=0
)
rows = pd.DataFrame({"seconds": [90, 150]})
checked = Sessions.validate(rows)
assert checked["minutes"].tolist() == [1.5, 2.5]
assert checked["minutes"].sum() == 4.0Separate missing data from a bad dependency graph
Consider an old export with a column called duration. A parser declared against seconds has no basis for assuming duration is in seconds. An explicit import adapter should handle that file version after checking the source contract. Guessing the unit can produce a perfectly valid numeric column with a sixtyfold error.
With derived columns that depend on other derived columns, Pandera orders the parsers by dependency. A missing parser source and a cycle have different meanings. The first calls for checking upstream names and input shape. A cycle, such as deriving minutes from hours while defining hours in terms of minutes, calls for changing the schema. Choose an independently supplied quantity as the root.
Keep one counterexample for each assumption
Start with the two-row example and inspect the validated output. Add a zero-duration row to check the lower boundary. Add a negative duration separately to confirm the range rule rejects it. Finally change one input column name. The expected failure is now about the data contract, even though the raw numbers did not change.
A nonnegative check by itself cannot distinguish seconds from minutes. Keep at least one fixture with a known physical answer; 90 seconds makes a particularly good example because integer division would silently lose the half minute. In production, aggregate the validated minutes only after deciding which rows belong to one session. Schema validation cannot decide whether duplicate export rows describe separate workouts.
Sources
Technical references checked .



