You are given a two-stage Python pipeline for temporal aggregation of event records.
The workflow accepts a list of event records, each with date (YYYY-MM-DD string), amount (float), and region (string).
Stage 1 — Parsing (parse_events):
Converts date strings to Date type
Extracts year, month, and quarter from each date
Returns an enriched in-memory DataFrame
Stage 2 — Aggregation (aggregate_by_period):
Groups by (year, month, region) and sums amounts → monthly breakdown
Groups by (year, quarter, region) and sums amounts → quarterly breakdown
The orchestrator (run_pipeline) calls both stages in sequence and returns a dict with "monthly" and "quarterly" keys.
Your Task
Port this pipeline to Modal. The two-stage design — a parsing helper called by an orchestrator, then an aggregation helper called with the parsed result — is a natural fit for a graph of remote functions where each stage is a distinct remote call.
The original workflow is in workflow.py.
Required Output
Write /app/solution/modal_app.py. It must:
Define a module-level app object
Define a module-level Modal Function named run_case
run_caseremote invocation (case) accepts a dict with key "records" (list of {date, amount, region} dicts)
Returns {"monthly": [...], "quarterly": [...]} matching the original output
Amount totals should be rounded to 4 decimal places. The remote environment needs polars installed.
Capability contract
Expose the workflow as a single Modal remote function: define run_case as an @app.function so the harness can invoke it with run_case.remote(case).