Skip to content

Commit

Permalink
Make MyPy somewhat happier
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Dec 21, 2023
1 parent 3b7b44c commit 042e595
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
25 changes: 12 additions & 13 deletions python/ribasim/ribasim/input_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
)

import geopandas as gpd
import numpy as np
import pandas as pd
import pandera as pa
from pandera.typing import DataFrame
Expand Down Expand Up @@ -204,10 +203,10 @@ def node_ids(self) -> set[int]:

return node_ids

def offset_node_ids(self, offset_node_id: int) -> "TableModel":
def offset_node_ids(self, offset_node_id: int) -> "TableModel[TableT]":
copy = deepcopy(self)
df = copy.df
if copy.df is not None:
if isinstance(df, (pd.DataFrame, gpd.GeoDataFrame)):
df.index += offset_node_id
for name_column in [

Check warning on line 211 in python/ribasim/ribasim/input_base.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/input_base.py#L207-L211

Added lines #L207 - L211 were not covered by tests
"node_id",
Expand All @@ -220,8 +219,8 @@ def offset_node_ids(self, offset_node_id: int) -> "TableModel":
return copy

Check warning on line 219 in python/ribasim/ribasim/input_base.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/input_base.py#L217-L219

Added lines #L217 - L219 were not covered by tests

def merge_table(
self, table_added: "TableModel", inplace: bool = True
) -> "TableModel":
self, table_added: "TableModel[TableT]", inplace: bool = True
) -> "TableModel[TableT]":
assert type(self) == type(

Check warning on line 224 in python/ribasim/ribasim/input_base.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/input_base.py#L224

Added line #L224 was not covered by tests
table_added
), "Can only merge tables of the same type."
Expand Down Expand Up @@ -492,9 +491,7 @@ def merge_node(self, node_added: "NodeModel", inplace: bool = True) -> "NodeMode
setattr(node, field, table_added)
return node

Check warning on line 492 in python/ribasim/ribasim/input_base.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/input_base.py#L491-L492

Added lines #L491 - L492 were not covered by tests

def delete_by_ids(
self, node_ids: np.ndarray[int], inplace: bool = True
) -> "NodeModel":
def delete_by_ids(self, node_ids: list[int], inplace: bool = True) -> "NodeModel":
if inplace:
node = self

Check warning on line 496 in python/ribasim/ribasim/input_base.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/input_base.py#L495-L496

Added lines #L495 - L496 were not covered by tests
else:
Expand All @@ -503,11 +500,13 @@ def delete_by_ids(
for field in node.fields():
attr = getattr(node, field)
if isinstance(attr, TableModel):
df = attr.df[~attr.df.node_id.isin(node_ids)]
if df.empty:
attr.df = None
else:
attr.df = df
df = attr.df
if isinstance(df, (pd.DataFrame, gpd.GeoDataFrame)):
df = df[~df.node_id.isin(node_ids)]
if df.empty:
attr.df = None

Check warning on line 507 in python/ribasim/ribasim/input_base.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/input_base.py#L500-L507

Added lines #L500 - L507 were not covered by tests
else:
attr.df = df

Check warning on line 509 in python/ribasim/ribasim/input_base.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/input_base.py#L509

Added line #L509 was not covered by tests

return node

Check warning on line 511 in python/ribasim/ribasim/input_base.py

View check run for this annotation

Codecov / codecov/patch

python/ribasim/ribasim/input_base.py#L511

Added line #L511 was not covered by tests

Expand Down
4 changes: 2 additions & 2 deletions python/ribasim/ribasim/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def offset_allocation_network_ids(

def add_edges(
self,
from_node_id: np.ndarray[int],
to_node_id: np.ndarray[int],
from_node_id: list[int],
to_node_id: list[int],
edge_type: list[str],
inplace: bool = True,
) -> "Network":
Expand Down

0 comments on commit 042e595

Please sign in to comment.