Schedule builtins¶
Rendered at build time from the continuous_gtfs.builtins.schedule package: its categories, each builtin's docstring, signature and declared findings. To change this page, change the code; the site is never edited by hand.
Parameterized steps for GTFS schedule tables, operating on Polars DataFrames in ctx.output. How conditions combine, how a missing column is reported, and the parameters every step shares are in the builtins guide.
| Builtin | Category | What it does |
|---|---|---|
InitScheduleOutput |
Init | Seed ctx.output from a schedule input before any other step runs. |
ClearField |
Row operations | Set one field to the empty string on the rows that match conditions. |
RemoveRows |
Row operations | Remove the rows of one file that match conditions. |
UpdateFields |
Row operations | Set field values on the rows of one file that match conditions. |
RemoveRoutes |
Semantic removals | Remove routes with their trips and everything a trip takes. |
RemoveServices |
Semantic removals | Remove services from both calendar files, with their trips. |
RemoveStops |
Semantic removals | Remove stops with their children and every row that references them. |
RemoveTrips |
Semantic removals | Remove trips with their stop_times, frequencies, attributions and transfers. |
SortRows |
Ordering | Order a file's rows so their order is a pure function of content. |
TransformTripId |
Identifiers | Rewrite every trip-id column across the schedule with a regex substitution. |
UpdateFeedInfo |
Feed metadata | Set publisher fields on every row of feed_info.txt. |
MatchCondition |
helper | One test on one field: an exact value or a regex pattern. |
SortKey |
helper | One SortRows key: which field, which direction, how values compare. |
Init¶
InitScheduleOutput
¶
InitScheduleOutput(
input_name: str = "schedule", **kwargs: Any
)
Seed ctx.output from a schedule input before any other step runs.
ctx.output starts empty; this step copies the named
gtfs_schedule_zip input into it so transforms have something to
mutate. ctx.inputs[input_name] stays as it was, so a step that wants
the pristine schedule (a supplemental merge, a diff) can still read it.
One of these replaces the @step(before="*") boilerplate every schedule
pipeline would otherwise carry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_name
|
str
|
The input to seed from, as declared in the pipeline's
|
'schedule'
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Note
Fails the run with a clear error when the named input was not
supplied, or is not a gtfs_schedule_zip (a mapping of file name
to DataFrame).
Examples:
# pipelines/schedule/init.py
from continuous_gtfs.builtins.schedule import InitScheduleOutput
init = InitScheduleOutput("schedule")
Row operations¶
ClearField
¶
ClearField(
file: str,
field: str,
conditions: list[MatchCondition]
| list[list[MatchCondition]],
*,
description: str = "",
**kwargs: Any,
)
Set one field to the empty string on the rows that match conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
The GTFS file to edit. |
required |
field
|
str
|
The column to clear. A column the file does not have is ignored. |
required |
conditions
|
list[MatchCondition] | list[list[MatchCondition]]
|
Which rows to clear, in the
|
required |
description
|
str
|
Label shown in the Console. Defaults to
|
''
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Note
A file absent from the output, or an empty conditions list, is a
silent no-op. A condition naming a column the file lacks leaves the
file untouched and emits column_missing, one per missing column.
Examples:
clear_blocks = ClearField(
"trips.txt",
"block_id",
[MatchCondition("route_id", value="COMMUTER_RAIL")],
description="Clear block_id for the commuter rail route",
)
Findings
| Finding | Subject | When |
|---|---|---|
column_missing |
file, column |
A condition or sort key named a column the file lacks; the step left the file untouched. |
RemoveRows
¶
RemoveRows(
file: str,
conditions: list[MatchCondition]
| list[list[MatchCondition]],
*,
exclude: list[list[MatchCondition]] | None = None,
description: str = "",
**kwargs: Any,
)
Remove the rows of one file that match conditions.
Mechanical: one file, one mask, no knowledge of what the rows mean. To remove a route, trip, stop, or service with everything that belongs to it, use a semantic removal instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
The GTFS file to edit, such as |
required |
conditions
|
list[MatchCondition] | list[list[MatchCondition]]
|
Which rows to remove: a flat list of
|
required |
exclude
|
list[list[MatchCondition]] | None
|
Groups in the same shape; a row matching any of them is protected from removal. |
None
|
description
|
str
|
Label shown in the Console. Defaults to
|
''
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Note
A file absent from the output, or an empty conditions list, is a
silent no-op. A condition naming a column the file lacks leaves the
file untouched and emits column_missing, one per missing column.
Examples:
remove_route = RemoveRows(
"routes.txt",
[MatchCondition("route_id", value="OLD_ROUTE")],
description="Remove deprecated route",
)
# Any-of: three stops in one step instead of three steps
remove_station_family = RemoveRows(
"stops.txt",
[
[MatchCondition("stop_id", value="S100")],
[MatchCondition("stop_id", value="S100-T1")],
[MatchCondition("stop_id", value="S100-T2")],
],
)
# Every RAIL service except the Spring 2026 one
remove_rail = RemoveRows(
"calendar.txt",
[MatchCondition("service_id", regex=r"^RAIL")],
exclude=[[MatchCondition("service_id", value="RAIL_SP26")]],
)
Findings
| Finding | Subject | When |
|---|---|---|
column_missing |
file, column |
A condition or sort key named a column the file lacks; the step left the file untouched. |
UpdateFields
¶
UpdateFields(
file: str,
conditions: list[MatchCondition]
| list[list[MatchCondition]],
updates: dict[str, str],
*,
description: str = "",
**kwargs: Any,
)
Set field values on the rows of one file that match conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
The GTFS file to edit. |
required |
conditions
|
list[MatchCondition] | list[list[MatchCondition]]
|
Which rows to update, in the
|
required |
updates
|
dict[str, str]
|
Column name to new value. A column the file does not have is ignored. |
required |
description
|
str
|
Label shown in the Console. Defaults to
|
''
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Note
A file absent from the output, or an empty conditions list, is a
silent no-op. A condition naming a column the file lacks leaves the
file untouched and emits column_missing, one per missing column.
Examples:
update_route = UpdateFields(
"routes.txt",
[MatchCondition("route_id", value="R1")],
{
"route_long_name": "Northside - Downtown",
"route_color": "007CAD",
"route_text_color": "FFFFFF",
},
description="Update route R1 metadata",
)
Findings
| Finding | Subject | When |
|---|---|---|
column_missing |
file, column |
A condition or sort key named a column the file lacks; the step left the file untouched. |
Semantic removals¶
RemoveRoutes
¶
RemoveRoutes(
conditions: Groups = None,
*,
ids: list[str] | None = None,
exclude: list[list[MatchCondition]] | None = None,
empty_services: Policy = "remove",
empty_shapes: Policy = "warn",
description: str = "",
**kwargs: Any,
)
Remove routes with their trips and everything a trip takes.
Removing a route removes its trips.txt rows (and their
stop_times.txt, frequencies.txt, attributions.txt and
transfers.txt rows), plus its fare_rules.txt, route_networks.txt,
attributions.txt and transfers.txt rows, transitively to a
fixpoint. Every removed id is written to ctx.id_mappings with a
None value so a custom step downstream can read what went away.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conditions
|
Groups
|
Which records to remove, in the
|
None
|
ids
|
list[str] | None
|
Key values to remove; the same as one any-of group per id.
Unions with |
None
|
exclude
|
list[list[MatchCondition]] | None
|
Groups in the same shape; a matching record is protected. |
None
|
empty_services
|
Policy
|
What to do with a service this step leaves with no
trips: |
'remove'
|
empty_shapes
|
Policy
|
The same for a shape left with no trips. Shapes are display geometry other trips may be re-pointed at, so the default keeps them. |
'warn'
|
description
|
str
|
Label shown in the Console. Defaults to
|
''
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Note
A missing routes.txt, or a selection that matches nothing, is a
silent no-op. A condition naming a column routes.txt lacks emits
column_missing and the step does nothing. A referencing file that
is absent, or lacks the referencing column, is skipped.
Examples:
remove_commuter = RemoveRoutes(ids=["COMMUTER_1", "COMMUTER_2"])
remove_shuttles = RemoveRoutes(
[MatchCondition("route_short_name", regex=r"Shuttle$")],
exclude=[[MatchCondition("route_id", value="SHUTTLE_KEEP")]],
)
Findings
| Finding | Subject | When |
|---|---|---|
rows_removed |
file |
Rows removed from a file: the root records (role=root), a cascade of what referenced them (cascade), or a prune of what they left empty (prune). The count is the rows removed. |
column_missing |
file, column |
A condition or sort key named a column the file lacks; the step left the file untouched. |
shape_without_trips |
shape_id |
This step left the shape with no trips and kept it (empty_shapes='warn'). |
RemoveServices
¶
RemoveServices(
conditions: Groups = None,
*,
ids: list[str] | None = None,
exclude: list[list[MatchCondition]] | None = None,
never_active: bool = False,
simplify_calendar: bool = True,
expired_before: bool | str | date = False,
empty_routes: Policy = "warn",
empty_shapes: Policy = "warn",
description: str = "",
**kwargs: Any,
)
Remove services from both calendar files, with their trips.
A service's rows in calendar.txt and calendar_dates.txt go
together, then its trips.txt rows and everything a trip takes.
Every removed id is written to ctx.id_mappings (services under
calendar.txt) with a None value.
Selection is by service_id only, evaluated over the union of service
ids in both calendar files so a regex reaches a service defined only
by exceptions. The selectors union; exclude protects a service from
every one of them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conditions
|
Groups
|
Condition groups whose every condition is on
|
None
|
ids
|
list[str] | None
|
Service ids to remove. Unions with |
None
|
exclude
|
list[list[MatchCondition]] | None
|
Groups in the same shape; a matching service is protected from every selector. |
None
|
never_active
|
bool
|
Also remove every service with no active date at
all, once its |
False
|
simplify_calendar
|
bool
|
With |
True
|
expired_before
|
bool | str | date
|
Also remove every service whose last active date
is strictly before a cutoff: |
False
|
empty_routes
|
Policy
|
What to do with a route this step leaves with no
trips: |
'warn'
|
empty_shapes
|
Policy
|
The same for a shape left with no trips. |
'warn'
|
description
|
str
|
Label shown in the Console. Defaults to a summary of the selectors. |
''
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Note
expired_before=True fails the step when the feed has no
feed_info.txt or no feed_start_date: a feed without one and no
configured cutoff is a data or configuration error, and the step
will not guess. No run date is ever consulted, so the same feed and
configuration produce the same output whenever the pipeline runs.
A selection that matches nothing is a silent no-op.
Examples:
drop_dead_services = RemoveServices(never_active=True)
drop_rail = RemoveServices(
[MatchCondition("service_id", regex=r"^RAIL")],
exclude=[[MatchCondition("service_id", value="RAIL_SP26")]],
)
# Everything that stopped running before this feed's feed_start_date
drop_expired = RemoveServices(expired_before=True)
# Pin the cutoff, and take the never-active calendars in the same step
drop_pre_fall = RemoveServices(expired_before="20260901", never_active=True)
Findings
| Finding | Subject | When |
|---|---|---|
rows_removed |
file |
Rows removed from a file: the root records (role=root), a cascade of what referenced them (cascade), or a prune of what they left empty (prune). The count is the rows removed. |
route_without_trips |
route_id |
This step left the route with no trips and kept it (empty_routes='warn'). |
shape_without_trips |
shape_id |
This step left the shape with no trips and kept it (empty_shapes='warn'). |
RemoveStops
¶
RemoveStops(
conditions: Groups = None,
*,
ids: list[str] | None = None,
exclude: list[list[MatchCondition]] | None = None,
children: ChildrenMode = "remove",
empty_trips: Policy = "remove",
empty_services: Policy = "remove",
empty_routes: Policy = "warn",
empty_shapes: Policy = "warn",
description: str = "",
**kwargs: Any,
)
Remove stops with their children and every row that references them.
A removed stop takes its stop_times.txt rows, its transfers.txt and
pathways.txt rows (either stop column), its stop_areas.txt rows,
and, by default, every row whose parent_station names it. Removing a
station therefore means the station: its platforms, entrances, nodes
and boarding areas go too, recursively. Every removed id is written to
ctx.id_mappings with a None value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conditions
|
Groups
|
Which records to remove, in the
|
None
|
ids
|
list[str] | None
|
Key values to remove; the same as one any-of group per id.
Unions with |
None
|
exclude
|
list[list[MatchCondition]] | None
|
Groups in the same shape; a matching record is protected. |
None
|
children
|
ChildrenMode
|
What to do with rows whose |
'remove'
|
empty_trips
|
Policy
|
What to do with a trip this step leaves with no
stop_times: |
'remove'
|
empty_services
|
Policy
|
The same for a service left with no trips. |
'remove'
|
empty_routes
|
Policy
|
The same for a route left with no trips. |
'warn'
|
empty_shapes
|
Policy
|
The same for a shape left with no trips. |
'warn'
|
description
|
str
|
Label shown in the Console. Defaults to
|
''
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Note
A missing stops.txt, or a selection that matches nothing, is a
silent no-op. A condition naming a column stops.txt lacks emits
column_missing and the step does nothing.
Examples:
# The whole station: platforms, entrances, and everything under it
remove_station = RemoveStops(ids=["S100"])
# Demote the station instead: platforms stay, entrances go
detach_station = RemoveStops(ids=["S100"], children="detach")
Findings
| Finding | Subject | When |
|---|---|---|
rows_removed |
file |
Rows removed from a file: the root records (role=root), a cascade of what referenced them (cascade), or a prune of what they left empty (prune). The count is the rows removed. |
column_missing |
file, column |
A condition or sort key named a column the file lacks; the step left the file untouched. |
trips_removed_with_stops |
— | Removing stops left trips with no stop_times, and those trips were removed too (empty_trips='remove'). The count is the trips. |
route_without_trips |
route_id |
This step left the route with no trips and kept it (empty_routes='warn'). |
shape_without_trips |
shape_id |
This step left the shape with no trips and kept it (empty_shapes='warn'). |
RemoveTrips
¶
RemoveTrips(
conditions: Groups = None,
*,
ids: list[str] | None = None,
exclude: list[list[MatchCondition]] | None = None,
empty_services: Policy = "remove",
empty_routes: Policy = "warn",
empty_shapes: Policy = "warn",
description: str = "",
**kwargs: Any,
)
Remove trips with their stop_times, frequencies, attributions and transfers.
Every removed id is written to ctx.id_mappings with a None value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conditions
|
Groups
|
Which records to remove, in the
|
None
|
ids
|
list[str] | None
|
Key values to remove; the same as one any-of group per id.
Unions with |
None
|
exclude
|
list[list[MatchCondition]] | None
|
Groups in the same shape; a matching record is protected. |
None
|
empty_services
|
Policy
|
What to do with a service this step leaves with no
trips: |
'remove'
|
empty_routes
|
Policy
|
The same for a route left with no trips. Agencies keep dormant routes on purpose (a bus bridge), so the default keeps it and warns. |
'warn'
|
empty_shapes
|
Policy
|
The same for a shape left with no trips. |
'warn'
|
description
|
str
|
Label shown in the Console. Defaults to
|
''
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Note
A missing trips.txt, or a selection that matches nothing, is a
silent no-op. A condition naming a column trips.txt lacks emits
column_missing and the step does nothing.
Examples:
remove_test_trips = RemoveTrips(
[MatchCondition("trip_id", regex=r"^TEST_")],
)
Findings
| Finding | Subject | When |
|---|---|---|
rows_removed |
file |
Rows removed from a file: the root records (role=root), a cascade of what referenced them (cascade), or a prune of what they left empty (prune). The count is the rows removed. |
column_missing |
file, column |
A condition or sort key named a column the file lacks; the step left the file untouched. |
route_without_trips |
route_id |
This step left the route with no trips and kept it (empty_routes='warn'). |
shape_without_trips |
shape_id |
This step left the shape with no trips and kept it (empty_shapes='warn'). |
Ordering¶
SortRows
¶
SortRows(
file: str,
by: Sequence[SortKey | str],
*,
description: str = "",
**kwargs: Any,
)
Order a file's rows so their order is a pure function of content.
Sorts by the given keys, then breaks every remaining tie by every column of the file in header order (ascending, as text). Two runs whose upstream steps hand the file over in different row orders therefore write byte-identical files, which is what keeps content-hash output versions stable. Use it on any file a merge or dedup step leaves in an order that varies between runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
The GTFS file to reorder. |
required |
by
|
Sequence[SortKey | str]
|
The sort keys, in precedence order: a
|
required |
description
|
str
|
Label shown in the Console. Defaults to
|
''
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Note
Defaults to after="*" so it runs after every other step that
touches the file; an explicit after=[...] is honored. Empty string
and null are one value and sort last in either direction. Header
order is untouched. A missing file is a silent no-op; a missing sort
field leaves the file unsorted and emits column_missing.
Examples:
sort_stop_times = SortRows(
"stop_times.txt",
["trip_id", SortKey("stop_sequence", numeric=True)],
)
Findings
| Finding | Subject | When |
|---|---|---|
column_missing |
file, column |
A condition or sort key named a column the file lacks; the step left the file untouched. |
sort_key_not_numeric |
file, column |
Values under a numeric sort key did not parse as numbers; they sorted last. The count is the number of such values. |
Identifiers¶
TransformTripId
¶
TransformTripId(
pattern: str, replacement: str, **kwargs: Any
)
Rewrite every trip-id column across the schedule with a regex substitution.
Operates on the three column names that carry trip references:
trip_id (trips.txt, stop_times.txt, frequencies.txt,
attributions.txt) and from_trip_id / to_trip_id
(transfers.txt). Any other column is left untouched.
Mirrors the realtime
TransformTripId:
both take the same (pattern, replacement) pair so an agency can
rewrite trip ids consistently across schedule and realtime outputs
(specs/configuration.md §Cross-pipeline shared modules).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
The regex to find, compiled by Polars (Rust |
required |
replacement
|
str
|
The replacement text; capture groups are |
required |
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Note
The realtime counterpart uses Python's re, where capture
references are \1. For a pattern shared between the two
pipelines, stay within the common subset (character classes,
alternation, anchors, quantifiers, () groups) and keep two
replacement strings, or avoid backreferences.
Examples:
shorten_trip_ids = TransformTripId(
pattern=r"^LONG_PREFIX_(\d+)$",
replacement=r"T-$1",
)
Feed metadata¶
UpdateFeedInfo
¶
UpdateFeedInfo(
*,
publisher_name: str | None = None,
publisher_url: str | None = None,
feed_lang: str | None = None,
**kwargs: Any,
)
Set publisher fields on every row of feed_info.txt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
publisher_name
|
str | None
|
New |
None
|
publisher_url
|
str | None
|
New |
None
|
feed_lang
|
str | None
|
New |
None
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Note
Only the fields given are written; a column the file lacks is
ignored, and a feed with no feed_info.txt is a silent no-op.
Examples:
update_feed = UpdateFeedInfo(
publisher_name="Example Transit",
publisher_url="https://transit.example.org",
feed_lang="en",
)
Helpers¶
Types the builtins above take as parameters.
MatchCondition
dataclass
¶
MatchCondition(
field: str,
value: str | None = None,
regex: str | None = None,
)
One test on one field: an exact value or a regex pattern.
Conditions select the rows a row-operation builtin acts on. They combine as groups: a flat list is one all-of group; a list of lists is any-of across groups. See the builtins guide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
The column the test reads. |
required |
value
|
str | None
|
Match rows whose field equals this string exactly. |
None
|
regex
|
str | None
|
Match rows whose field contains a match for this pattern
(Polars |
None
|
Examples:
MatchCondition("route_id", value="R2")
MatchCondition("service_id", regex=r"^RAIL")
SortKey
dataclass
¶
SortKey(
field: str,
descending: bool = False,
numeric: bool = False,
)
One SortRows key: which field, which direction, how values compare.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
str
|
The column to sort by. |
required |
descending
|
bool
|
Sort this key high to low. |
False
|
numeric
|
bool
|
Compare the values as numbers ( |
False
|
Examples:
SortKey("stop_sequence", numeric=True)
SortKey("start_date", descending=True)