Skip to content

Commit

Permalink
Fix example Network - add back in "ref"
Browse files Browse the repository at this point in the history
- Accidentally deleted 'ref' from st paul roadway links b/c wasn't in data model even though it is used.
- Added to data model since it is a key OSM field as optional and updated example network to include it.
- Updated error checking for the dict query to make sure it is explicitly telling you the field doesn't exist in the df you are querying
  • Loading branch information
e-lo committed Oct 17, 2024
1 parent 6602dd7 commit 8bed3cc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
Binary file modified .coverage
Binary file not shown.
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
--benchmark-save=pr_benchmark \
--benchmark-json=pr_benchmark.json \
--cov-report=term-missing:skip-covered \
--cov=network_wrangler tests/ | \
tee pytest-coverage.txt
--cov=network_wrangler tests/ 2>&1 | \
tee -a pytest-coverage.txt
- name: Pytest coverage comment
if: github.event_name == 'pull_request'
uses: MishaKav/pytest-coverage-comment@main
Expand Down
2 changes: 1 addition & 1 deletion examples/stpaul/link.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion network_wrangler/models/roadway/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class RoadLinksTable(DataFrameModel):
price: Series[float] = pa.Field(coerce=True, nullable=False, default=0)

# Optional Fields

ref: Optional[Series[str]] = pa.Field(coerce=True, nullable=True, default=None)
access: Optional[Series[Any]] = pa.Field(coerce=True, nullable=True, default=None)

sc_lanes: Optional[Series[object]] = pa.Field(coerce=True, nullable=True, default=None)
Expand Down
12 changes: 10 additions & 2 deletions network_wrangler/utils/df_accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pandas as pd

from ..errors import SelectionError
from ..logger import WranglerLogger
from .data import dict_to_query, isin_dict

Expand Down Expand Up @@ -39,15 +40,22 @@ def __call__(self, selection_dict: dict, return_all_if_none: bool = False):
return_all_if_none (bool, optional): If True, will return entire df if dict has
no values. Defaults to False.
"""
_not_selection_keys = ["modes", "all", "ignore_missing"]
_selection_dict = {
k: v for k, v in selection_dict.items() if k in self._obj.columns and v is not None
k: v
for k, v in selection_dict.items()
if k not in _not_selection_keys and v is not None
}
missing_columns = [k for k in _selection_dict if k not in self._obj.columns]
if missing_columns:
msg = f"Selection fields not found in dataframe: {missing_columns}"
raise SelectionError(msg)

if not _selection_dict:
if return_all_if_none:
return self._obj
msg = f"Relevant part of selection dictionary is empty: {selection_dict}"
raise ValueError(msg)
raise SelectionError(msg)

_sel_query = dict_to_query(_selection_dict)
# WranglerLogger.debug(f"_sel_query: \n {_sel_query}")
Expand Down

0 comments on commit 8bed3cc

Please sign in to comment.