Unified semantic audit on canonical frames: static (A1–A7) and, if given, dynamic (D1–D3).
A pure function (no feed object), so it audits feeds you fetched yourself or frames read
back from a Parquet lake. Results are stacked with an audit_type column. Use
audit_static / audit_dynamic directly for the per-rule boolean columns.
See Also
audit_static : The static A1-A7 half, with per-rule boolean columns.
audit_dynamic : The dynamic D1-D3 half, with per-rule boolean columns.
drop_flagged : Keep only the stations that pass the static audit.
Examples:
>>> import pandas as pd
>>> info = pd.DataFrame({
... "system_id": "s", "station_id": ["a", "b"],
... "station_type": ["docked_bike", "carsharing"],
... "capacity": [20, 5], "lat": [48.85, 48.86], "lon": [2.35, 2.36],
... })
>>> audit_frames(info)[["station_id", "audit_type", "flagged"]]
station_id audit_type flagged
0 a static False
1 b static True
Source code in src/gbfs_toolkit/audit/__init__.py
| def audit_frames(
info: pd.DataFrame,
status: pd.DataFrame | None = None,
*,
ttl_seconds: int | None = None,
system_id: str = "system",
) -> pd.DataFrame:
"""Unified semantic audit on canonical frames: static (A1–A7) and, if given, dynamic (D1–D3).
A pure function (no feed object), so it audits feeds you fetched yourself *or* frames read
back from a Parquet lake. Results are stacked with an ``audit_type`` column. Use
[`audit_static`][gbfs_toolkit.audit_static] / [`audit_dynamic`][gbfs_toolkit.audit_dynamic] directly for the per-rule boolean columns.
See Also
--------
[`audit_static`][gbfs_toolkit.audit_static] : The static A1-A7 half, with per-rule boolean columns.
[`audit_dynamic`][gbfs_toolkit.audit_dynamic] : The dynamic D1-D3 half, with per-rule boolean columns.
[`drop_flagged`][gbfs_toolkit.drop_flagged] : Keep only the stations that pass the static audit.
Examples
--------
>>> import pandas as pd
>>> info = pd.DataFrame({
... "system_id": "s", "station_id": ["a", "b"],
... "station_type": ["docked_bike", "carsharing"],
... "capacity": [20, 5], "lat": [48.85, 48.86], "lon": [2.35, 2.36],
... })
>>> audit_frames(info)[["station_id", "audit_type", "flagged"]] # doctest: +NORMALIZE_WHITESPACE
station_id audit_type flagged
0 a static False
1 b static True
"""
static = audit_static(info).assign(audit_type="static")
parts = [static[AUDIT_RESULT_COLUMNS]]
if status is not None and len(status):
from gbfs_toolkit.analytics.frames import join_availability
availability = join_availability(info, status)
dynamic = audit_dynamic(availability, ttl_seconds=ttl_seconds).assign(
audit_type="dynamic", system_id=system_id
)
parts.append(dynamic[AUDIT_RESULT_COLUMNS])
return pd.concat(parts, ignore_index=True)
|