Skip to content

filter_catalog

filter_catalog

filter_catalog(catalog: DataFrame, *, country_code: str | None = None, city: str | None = None, name: str | None = None) -> DataFrame

Filter the systems catalogue, because you know "Paris", not the system_id.

All filters are case-insensitive; city / name match as substrings against the catalogue's location / name columns (whichever are present).

See Also

systems_catalog : The full catalogue this filters. resolve : Resolve a filtered system.

Source code in src/gbfs_toolkit/io/catalog.py
def filter_catalog(
    catalog: pd.DataFrame,
    *,
    country_code: str | None = None,
    city: str | None = None,
    name: str | None = None,
) -> pd.DataFrame:
    """Filter the systems catalogue, because you know "Paris", not the system_id.

    All filters are case-insensitive; ``city`` / ``name`` match as substrings against
    the catalogue's ``location`` / ``name`` columns (whichever are present).

    See Also
    --------
    [`systems_catalog`][gbfs_toolkit.systems_catalog] : The full catalogue this filters.
    [`resolve`][gbfs_toolkit.resolve] : Resolve a filtered system.
    """
    out = catalog
    if country_code is not None and "country_code" in out.columns:
        out = out[out["country_code"].astype(str).str.lower() == country_code.lower()]
    if city is not None:
        col = next((c for c in ("location", "city", "name") if c in out.columns), None)
        if col:
            out = out[out[col].astype(str).str.contains(city, case=False, na=False)]
    if name is not None and "name" in out.columns:
        out = out[out["name"].astype(str).str.contains(name, case=False, na=False)]
    return out.reset_index(drop=True)