Skip to content

Commit

Permalink
Trim header column names, added Metra test (#152)
Browse files Browse the repository at this point in the history
* Trim header column names, added Metra test

Metra would not load and I was getting complaints about that.
The header looks like
stop_id, stop_name, stop_desc, stop_lat, stop_lon, zone_id, stop_url, wheelchair_boarding
and thus ` stop_name` is not eq to `stop_name`.

This resolves this issue by trimming the header column names for every file.
  • Loading branch information
kylerchin authored Jan 1, 2024
1 parent ee87da9 commit 9fc3af3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
description = "Read GTFS (public transit timetables) files"
name = "gtfs-structures"
version = "0.39.0"
version = "0.39.1"
authors = ["Tristram Gräbener <[email protected]>", "Antoine Desbordes <[email protected]>"]
repository = "https://github.com/rust-transit/gtfs-structure"
license = "MIT"
Expand Down
Binary file added fixtures/zips/metra.zip
Binary file not shown.
5 changes: 4 additions & 1 deletion src/gtfs_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,10 @@ impl RawGtfsReader {
source: e,
line_in_error: None,
})?
.clone();
.clone()
.into_iter()
.map(|x| x.trim())
.collect::<csv::StringRecord>();

// Pre-allocate a StringRecord for performance reasons
let mut rec = csv::StringRecord::new();
Expand Down
14 changes: 14 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,20 @@ fn read_only_required_fields() {
)
}

#[test]
fn metra_gtfs() {
let gtfs = Gtfs::from_path("fixtures/zips/metra.zip");

match &gtfs {
Err(err) => {
eprintln!("{:#?}", err);
}
_ => {}
}

assert!(gtfs.is_ok());
}

#[test]
fn sorted_shapes() {
let gtfs = Gtfs::from_path("fixtures/basic").expect("impossible to read gtfs");
Expand Down

0 comments on commit 9fc3af3

Please sign in to comment.