Skip to content

Commit

Permalink
fix: add condition to prevent operating on emty dataframe in consolid…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
Christian committed Aug 18, 2023
1 parent b7a55c9 commit f073aec
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
39 changes: 20 additions & 19 deletions osm4gpd/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,26 @@ def consolidate_relations(
crs="EPSG:4326",
)

relations = pd.concat(
[
relations,
gpd.GeoDataFrame.from_dict(
{
idx: {
"geometry": func(relations=relations.set_index("id")),
"version": group.version[idx],
"changeset": group.version[idx],
"visible": group.version[idx],
"id": group.ids[idx],
}
for idx, func in unresolved
},
orient="index",
crs="EPSG:4326",
),
]
)
if len(unresolved) > 0:
relations = pd.concat(
[
relations,
gpd.GeoDataFrame.from_dict(
{
idx: {
"geometry": func(relations=relations.set_index("id")),
"version": group.version[idx],
"changeset": group.version[idx],
"visible": group.version[idx],
"id": group.ids[idx],
}
for idx, func in unresolved
},
orient="index",
crs="EPSG:4326",
),
]
)

return relations.join(
pd.DataFrame.from_dict(
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ def isle_of_man(shared_datadir: Path) -> Path:
@pytest.fixture
def malta(shared_datadir: Path) -> Path:
return shared_datadir.joinpath("malta-latest.osm.pbf")


@pytest.fixture
def extract(shared_datadir: Path) -> Path:
return shared_datadir.joinpath("extract.osm.pbf")
Binary file added tests/data/extract.osm.pbf
Binary file not shown.
1 change: 1 addition & 0 deletions tests/test_consolidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@pytest.mark.parametrize(
"filename,tags,expected_shape",
[
("extract", {"amenity"}, (1184, 157)),
("isle_of_man", {"name"}, (102488, 1109)),
("malta", {"amenity"}, (19247, 354)),
("malta", {"car_wash"}, (10, 8)),
Expand Down

0 comments on commit f073aec

Please sign in to comment.