Schema¶
The adapter layer that converts ISO-specific trade DataFrames into the canonical format expected by the metrics pipeline. Each ISO registers an ISOTradeSchema instance that declares its column mapping, gain-normalization function, and optional validation hooks.
Adaptation Steps¶
- Validate that all required ISO columns exist.
- Rename ISO columns to canonical names using the inverse of
column_map. - Enforce datetime dtype on
interval_start_local. - Compute
gain_normalizedvia the registeredgain_normalizercallable. - Derive
datefrominterval_start_local. - Add a constant
isocolumn. - Run any
extra_validations.
ISO Trade Schema - Adapter layer for converting ISO-specific DataFrames to canonical format.
Classes¶
ISOTradeSchema
dataclass
¶
ISOTradeSchema(iso_name: str, column_map: Mapping[str, str], gain_normalizer: GainNormalizer, capital_requirement_fn: CapitalRequirementFn | None = None, extra_validations: list[Callable[[DataFrame], None]] = list())
Schema definition for adapting ISO-specific trade DataFrames to canonical format.
Attributes: iso_name: Name of the ISO (e.g., "MISO", "ERCOT", "SPP") column_map: Mapping from canonical column names to ISO-specific column names gain_normalizer: Callable that computes gain_normalized from the DataFrame capital_requirement_fn: Optional callable to compute capital requirement extra_validations: List of validation functions to run on the adapted DataFrame
Functions¶
adapt_frame
¶
Adapt an ISO-specific DataFrame to the canonical format.
Steps: 1. Validate required columns exist (using self.column_map.values()) 2. Rename ISO columns to canonical names (inverse mapping) 3. Enforce dtypes (datetime64[ns], booleans, floats) 4. Create 'gain_normalized' via self.gain_normalizer(df_renamed) 5. Add 'date' = df_renamed["interval_start_local"].dt.date 6. Add constant column 'iso' = self.iso_name 7. Run any extra_validations 8. Return a new DataFrame (do not mutate input)
Args: df_iso: ISO-specific DataFrame
Returns: Standardized DataFrame with canonical columns
Source code in src/progridpy/metrics/schema.py
compute_capital_requirement
¶
Compute the capital requirement for the given standardized DataFrame.
Args: df_std: Standardized DataFrame (should be filtered to cleared trades)
Returns: Capital requirement value, or None if no capital_requirement_fn is defined