Skip to content

to_canonical_pricing_plans

to_canonical_pricing_plans

to_canonical_pricing_plans(raw: dict, *, system_id: str) -> DataFrame

Parse system_pricing_plans.json into a canonical lookup table.

Resolves the pricing_plan_id foreign key carried on vehicles, so cost / equity studies can join price to availability. Returns PRICING_PLAN_COLUMNS; name/description are localised via the same v2/v3 heuristic as elsewhere.

See Also

to_canonical_vehicles : The vehicles these plans price.

Source code in src/gbfs_toolkit/io/normalize.py
def to_canonical_pricing_plans(raw: dict, *, system_id: str) -> pd.DataFrame:
    """Parse ``system_pricing_plans.json`` into a canonical lookup table.

    Resolves the ``pricing_plan_id`` foreign key carried on vehicles, so cost / equity
    studies can join price to availability. Returns
    `PRICING_PLAN_COLUMNS`; ``name``/``description`` are localised
    via the same v2/v3 heuristic as elsewhere.

    See Also
    --------
    [`to_canonical_vehicles`][gbfs_toolkit.to_canonical_vehicles] : The vehicles these plans price.
    """
    data = raw.get("data", raw)
    plans = _records(data, "plans")
    rows = [
        {
            "system_id": system_id,
            "plan_id": str(p.get("plan_id")),
            "name": _name(p.get("name")),
            "currency": p.get("currency"),
            "price": p.get("price"),
            "is_taxable": p.get("is_taxable"),
            "description": _name(p.get("description")),
        }
        for p in plans
    ]
    df = pd.DataFrame(rows, columns=PRICING_PLAN_COLUMNS)
    df["price"] = pd.to_numeric(df["price"], errors="coerce")
    df["is_taxable"] = df["is_taxable"].astype("boolean")
    return df