Skip to content

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 INPUTS manifest.

'schedule'
**kwargs Any

Shared step parameters (after, before, priority, enabled, tags, data_owner); see Step. A before= argument is ignored: this step always runs first.

{}
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 RemoveRows group shape.

required
description str

Label shown in the Console. Defaults to Clear <field> in <file>.

''
**kwargs Any

Shared step parameters (after, before, priority, enabled, tags, data_owner); see Step.

{}
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 "routes.txt".

required
conditions list[MatchCondition] | list[list[MatchCondition]]

Which rows to remove: a flat list of MatchCondition (all must hold) or a list of lists (any group may hold).

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 Remove rows from <file>.

''
**kwargs Any

Shared step parameters (after, before, priority, enabled, tags, data_owner); see Step.

{}
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 RemoveRows group shape.

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 Update fields in <file>.

''
**kwargs Any

Shared step parameters (after, before, priority, enabled, tags, data_owner); see Step.

{}
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 RemoveRows group shape, evaluated on the record's home file.

None
ids list[str] | None

Key values to remove; the same as one any-of group per id. Unions with conditions. One of the two is required.

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", "warn" (keep it and emit a warning naming it), or "keep".

'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 Remove routes.

''
**kwargs Any

Shared step parameters (after, before, priority, enabled, tags, data_owner); see Step.

{}
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 service_id (value or regex). A condition on any other column raises at construction.

None
ids list[str] | None

Service ids to remove. Unions with conditions and the selectors below.

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 calendar.txt weekday flags over its date range and its calendar_dates.txt adds and removals are resolved together: an all-zero calendar row with no added dates, or a row whose every in-range service day is cancelled.

False
simplify_calendar bool

With never_active, a service kept alive only by calendar_dates.txt adds is not removed; its dead all-zero calendar.txt row is dropped and its exception rows kept. False leaves that row alone.

True
expired_before bool | str | date

Also remove every service whose last active date is strictly before a cutoff: True for the feed's own feed_info.txt feed_start_date, or an explicit "YYYYMMDD" string or date. Exception rows dated before the cutoff on services that survive are removed as well, counted in calendar_dates.txt's rows_removed. A service with no active date at all is never_active's, not this selector's; combine the two in one step for both.

False
empty_routes Policy

What to do with a route this step leaves with no trips: "remove", "warn" (keep it and emit a warning naming it), or "keep".

'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 (after, before, priority, enabled, tags, data_owner); see Step.

{}
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 RemoveRows group shape, evaluated on the record's home file.

None
ids list[str] | None

Key values to remove; the same as one any-of group per id. Unions with conditions. One of the two is required.

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 parent_station names a removed stop. "remove" takes them too, recursively. "detach" clears parent_station on platforms (location type blank or 0) so they stand alone, and still removes entrances, generic nodes and boarding areas, which cannot exist without a parent.

'remove'
empty_trips Policy

What to do with a trip this step leaves with no stop_times: "remove", "warn" (keep it and emit a warning naming it), or "keep". Under the default the trips are removed and a trips_removed_with_stops warning says how many; what those trips emptied then follows the RemoveTrips defaults.

'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 Remove stops.

''
**kwargs Any

Shared step parameters (after, before, priority, enabled, tags, data_owner); see Step.

{}
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 RemoveRows group shape, evaluated on the record's home file.

None
ids list[str] | None

Key values to remove; the same as one any-of group per id. Unions with conditions. One of the two is required.

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", "warn" (keep it and emit a warning naming it), or "keep". A service with no trips is dead data, so the default removes it.

'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 Remove trips.

''
**kwargs Any

Shared step parameters (after, before, priority, enabled, tags, data_owner); see Step.

{}
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 SortKey, or a bare column name as shorthand for an ascending text key.

required
description str

Label shown in the Console. Defaults to Sort <file> by <keys>.

''
**kwargs Any

Shared step parameters (after, before, priority, enabled, tags, data_owner); see Step.

{}
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 regex syntax).

required
replacement str

The replacement text; capture groups are $1, $2.

required
**kwargs Any

Shared step parameters (after, before, priority, enabled, tags, data_owner); see Step.

{}
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 feed_publisher_name.

None
publisher_url str | None

New feed_publisher_url.

None
feed_lang str | None

New feed_lang.

None
**kwargs Any

Shared step parameters (after, before, priority, enabled, tags, data_owner); see Step.

{}
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 str.contains, Rust regex syntax; anchor with ^ and $ to match the whole value). Give value or regex, not both.

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 (9 before 10) instead of as text (10 before 9). The cast is for comparison only; the written values are never touched. A value that does not parse sorts last and is counted in a sort_key_not_numeric finding.

False

Examples:

SortKey("stop_sequence", numeric=True)
SortKey("start_date", descending=True)