diff --git a/README.rst b/README.rst index b632053..f0599d5 100644 --- a/README.rst +++ b/README.rst @@ -146,10 +146,11 @@ Notes Changes ======== -4.0.5, 2022-YY-DD +4.0.5, 2022-11-08 ----------------- - Removed most type coercion in validation. Probably more instructive for the user that way. +- Fixed `Issue 11 `_. 4.0.4, 2022-10-19 diff --git a/data/auckland/speed_zones.geojson b/data/auckland/speed_zones.geojson index e861e18..236e8ff 100644 --- a/data/auckland/speed_zones.geojson +++ b/data/auckland/speed_zones.geojson @@ -1,129 +1 @@ -{ - "type": "FeatureCollection", - "features": [ - { - "type": "Feature", - "properties": { - "speed": 200, - "speed_zone_id": "a", - "route_type": 3 - }, - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - 174.76552963256836, - -36.84198795415702 - ], - [ - 174.7753143310547, - -36.86671222190732 - ], - [ - 174.78355407714844, - -36.858334338156325 - ], - [ - 174.76552963256836, - -36.84198795415702 - ] - ] - ] - } - }, - { - "type": "Feature", - "properties": { - "speed": 100, - "speed_zone_id": "b", - "route_type": 3 - }, - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - 174.76106643676758, - -36.84294960290717 - ], - [ - 174.73634719848633, - -36.868497553806066 - ], - [ - 174.76982116699216, - -36.867261559242756 - ], - [ - 174.76106643676758, - -36.84294960290717 - ] - ] - ] - } - }, - { - "type": "Feature", - "properties": { - "speed": 100, - "speed_zone_id": "b", - "route_type": 2 - }, - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - 174.76106643676758, - -36.84294960290717 - ], - [ - 174.73634719848633, - -36.868497553806066 - ], - [ - 174.76982116699216, - -36.867261559242756 - ], - [ - 174.76106643676758, - -36.84294960290717 - ] - ] - ] - } - }, - { - "type": "Feature", - "properties": { - "speed": 200, - "speed_zone_id": "c", - "route_type": 2 - }, - "geometry": { - "type": "Polygon", - "coordinates": [ - [ - [ - 174.75831985473633, - -36.843636487467585 - ], - [ - 174.72707748413083, - -36.84913134182603 - ], - [ - 174.73257064819336, - -36.86616288062215 - ], - [ - 174.75831985473633, - -36.843636487467585 - ] - ] - ] - } - } - ] -} \ No newline at end of file +{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"shape_id":"","speed_zone_id":"b","route_type":3,"speed":100},"geometry":{"coordinates":[[[174.76736043357516,-36.84179324765078],[174.7557411745173,-36.85934428591189],[174.77803528270158,-36.87180496532289],[174.79034130103025,-36.85339076851254],[174.76736043357516,-36.84179324765078]]],"type":"Polygon"}},{"type":"Feature","properties":{"shape_id":"","speed_zone_id":"b","route_type":2,"speed":100},"geometry":{"coordinates":[[[174.76736043357516,-36.84179324765078],[174.7557411745173,-36.85934428591189],[174.77803528270158,-36.87180496532289],[174.79034130103025,-36.85339076851254],[174.76736043357516,-36.84179324765078]]],"type":"Polygon"}},{"type":"Feature","properties":{"speed_zone_id":"a","route_type":3,"speed":200},"geometry":{"coordinates":[[[174.74412069842128,-36.84729893247791],[174.73515720368863,-36.84663909049593],[174.74973178543615,-36.860554159183835],[174.7518536704664,-36.8563292730222],[174.74412069842128,-36.84729893247791]]],"type":"Polygon"}}]} \ No newline at end of file diff --git a/make_gtfs/main.py b/make_gtfs/main.py index 782c727..ee57ab2 100644 --- a/make_gtfs/main.py +++ b/make_gtfs/main.py @@ -485,7 +485,11 @@ def compute_dists(group): for shape_id, group in shapes_g.groupby("shape_id"): bd = group.boundary_points.iat[0] if bd and not bd.is_empty: - for point in bd.geoms: + if isinstance(bd, sg.Point): + bpoints = [bd] + else: + bpoints = bd.geoms + for point in bpoints: dist = group.geometry.iat[0].project(point) rows.append([shape_id, dist, point]) @@ -773,7 +777,9 @@ def build_feed( calendar, service_by_window = build_calendar_etc(pfeed) routes = build_routes(pfeed) shapes = build_shapes(pfeed) - stops = build_stops(pfeed, shapes, offset=stop_offset, n=num_stops_per_shape, spacing=stop_spacing) + stops = build_stops( + pfeed, shapes, offset=stop_offset, n=num_stops_per_shape, spacing=stop_spacing + ) trips = build_trips(pfeed, routes, service_by_window) stop_times = build_stop_times(pfeed, routes, shapes, stops, trips, buffer=buffer) diff --git a/notebooks/examples.ipynb b/notebooks/examples.ipynb index dfc3a24..f7a0b23 100644 --- a/notebooks/examples.ipynb +++ b/notebooks/examples.ipynb @@ -120,7 +120,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.7" + "version": "3.10.8" } }, "nbformat": 4, diff --git a/tests/test_validators.py b/tests/test_validators.py index b551cae..107bda9 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -147,10 +147,11 @@ def test_check_speed_zones(): with pytest.raises(pa.errors.SchemaError): check_speed_zones(pfeed) - # Check coercion - # pfeed = sample.copy() - # pfeed.speed_zones["route_type"].iat[0] = 3 - # assert isinstance(check_speed_zones(pfeed), pd.DataFrame) + # Set bad route type + pfeed = sample.copy() + pfeed.speed_zones["route_type"].iat[0] = "3" + with pytest.raises(pa.errors.SchemaError): + check_speed_zones(pfeed) # Make speed zones IDs collide within a route type pfeed = sample.copy()