Skip to content

Commit

Permalink
Linting!
Browse files Browse the repository at this point in the history
  • Loading branch information
e-lo committed Jul 16, 2024
1 parent 6193bf5 commit fa18f1a
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 7,709 deletions.
12 changes: 4 additions & 8 deletions network_wrangler/models/_base/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,16 @@ def fields_as_fks(cls) -> list[str]:
return pks_as_fks

def check_referenced_fk(
self,
pk_table_name,
pk_field: str,
pk_table: Optional[pd.DataFrame] = None
self, pk_table_name, pk_field: str, pk_table: Optional[pd.DataFrame] = None
) -> bool:
"""True if table.field has the values referenced in any table referencing fields as fk.
For example. If routes.route_id is referenced in trips table, we need to check that
if a route_id is deleted, it isn't referenced in trips.route_id.
"""
WranglerLogger.debug(
f"Checking tables which referenced {pk_table_name}.{pk_field} as an FK")
f"Checking tables which referenced {pk_table_name}.{pk_field} as an FK"
)
if pk_table is None:
pk_table = self.get_table(pk_table_name)

Expand Down Expand Up @@ -289,9 +287,7 @@ def check_table_fks(
all_valid = False
continue
if len(pkref_table) < 10:
WranglerLogger.debug(
f"PK values:\n{pkref_table[pkref_field]}."
)
WranglerLogger.debug(f"PK values:\n{pkref_table[pkref_field]}.")
WranglerLogger.debug(f"Checking {table_name}.{field} foreign key")
valid, missing = fk_in_pk(pkref_table[pkref_field], table[field])
if missing:
Expand Down
2 changes: 1 addition & 1 deletion network_wrangler/models/projects/roadway_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class SelectLinksDict(RecordModel):
"ref",
"osm_link_id",
"model_link_id",
"modes"
"modes",
]
_special_fields: ClassVar[list[str]] = ["modes", "ignore_missing"]
model_config = ConfigDict(extra="allow")
Expand Down
7 changes: 6 additions & 1 deletion network_wrangler/roadway/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@
from ..models.projects.roadway_selection import SelectLinksDict, SelectNodesDict, SelectFacility
from ..models.projects.roadway_property_change import NodeGeometryChangeTable
from ..utils.models import empty_df_from_datamodel
from .selection import RoadwayLinkSelection, RoadwayNodeSelection, _create_selection_key, SelectionError
from .selection import (
RoadwayLinkSelection,
RoadwayNodeSelection,
_create_selection_key,
SelectionError,
)
from .model_roadway import ModelRoadwayNetwork
from .nodes.create import data_to_nodes_df
from .links.create import data_to_links_df
Expand Down
4 changes: 2 additions & 2 deletions network_wrangler/roadway/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def selection_dict(self) -> dict:

@selection_dict.setter
def selection_dict(self, selection_input: Union[SelectFacility, dict]):

if isinstance(selection_input, SelectLinksDict):
selection_input = SelectFacility(links=selection_input)
elif isinstance(selection_input, SelectNodesDict):
Expand Down Expand Up @@ -483,7 +482,8 @@ def _select_explicit_node_id(


def _create_selection_key(
selection_dict: Union[SelectLinksDict, SelectNodesDict, SelectFacility, dict]) -> str:
selection_dict: Union[SelectLinksDict, SelectNodesDict, SelectFacility, dict],
) -> str:
"""Selections are stored by a sha1 hash of the bit-encoded string of the selection dictionary.
Args:
Expand Down
14 changes: 8 additions & 6 deletions network_wrangler/roadway/subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
DEFAULT_MAX_SEARCH_BREADTH,
DEFAULT_SP_WEIGHT_COL,
)
from ..models.projects.roadway_selection import SelectLinksDict, SelectFacility, SelectNodesDict, SelectNodeDict
from ..models.projects.roadway_selection import (
SelectLinksDict,
SelectFacility,
SelectNodesDict,
SelectNodeDict,
)
from ..logger import WranglerLogger

if TYPE_CHECKING:
Expand Down Expand Up @@ -243,7 +248,7 @@ def _expand_subnet_breadth(self) -> None:


def _generate_subnet_link_selection_dict_options(
link_selection_dict: dict
link_selection_dict: dict,
) -> list[SelectLinksDict]:
"""Generates a list of link selection dictionaries based on a link selection dictionary.
Expand Down Expand Up @@ -312,10 +317,7 @@ def generate_subnet_from_link_selection_dict(

subnet_links_df["i"] = 0
subnet = Subnet(
net=net,
subnet_links_df=subnet_links_df,
modes=link_selection_data.modes,
**kwargs
net=net, subnet_links_df=subnet_links_df, modes=link_selection_data.modes, **kwargs
)

WranglerLogger.info(
Expand Down
5 changes: 3 additions & 2 deletions network_wrangler/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,9 @@ def coerce_val_to_series_type(val, s: pd.Series):
return v


def fk_in_pk(pk: Union[pd.Series, list], fk: Union[pd.Series, list], ignore_nan: bool = True
) -> Tuple[bool, list]:
def fk_in_pk(
pk: Union[pd.Series, list], fk: Union[pd.Series, list], ignore_nan: bool = True
) -> Tuple[bool, list]:
"""Check if all foreign keys are in the primary keys, optionally ignoring NaN."""
if isinstance(fk, list):
fk = pd.Series(fk)
Expand Down
Loading

0 comments on commit fa18f1a

Please sign in to comment.