Skip to content

Commit

Permalink
Exclude fewer Ruff rules (#1955)
Browse files Browse the repository at this point in the history
Mainly centered around our docstrings, so this helps with #219.
  • Loading branch information
visr authored Dec 2, 2024
1 parent 7000193 commit 7d8e7a4
Show file tree
Hide file tree
Showing 27 changed files with 60 additions and 136 deletions.
1 change: 1 addition & 0 deletions python/ribasim/ribasim/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Results(ChildModel):
class Solver(ChildModel):
"""
Defines the numerical solver options.
For more details see <https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/#solver_options>.
Attributes
Expand Down
1 change: 0 additions & 1 deletion python/ribasim/ribasim/delwaq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"generate",
"parse",
"run_delwaq",
"plot",
"add_tracer",
"plot_fraction",
"plot_spatial",
Expand Down
3 changes: 1 addition & 2 deletions python/ribasim/ribasim/delwaq/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def _quote(value):
def _make_boundary(data, boundary_type):
"""
Create a Delwaq boundary definition with the given data and boundary type.
Pivot our data from long to wide format, and convert the time to a string.
Pivot our data from long to wide format, and convert the time to a string.
Specifically, we go from a table:
`node_id, substance, time, concentration`
to
Expand Down Expand Up @@ -300,7 +300,6 @@ def generate(
output_path: Path = output_path,
) -> tuple[nx.DiGraph, set[str]]:
"""Generate a Delwaq model from a Ribasim model and results."""

# Read in model and results
model = ribasim.Model.read(toml_path)
results_folder = toml_path.parent / model.results_dir
Expand Down
7 changes: 4 additions & 3 deletions python/ribasim/ribasim/geometry/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ def add(
edge_id: Optional[NonNegativeInt] = None,
**kwargs,
):
"""Add an edge between nodes. The type of the edge (flow or control)
is automatically inferred from the type of the `from_node`.
"""
Add an edge between nodes.
The type of the edge (flow or control) is automatically inferred from the type of the `from_node`.
Parameters
----------
Expand Down Expand Up @@ -185,7 +187,6 @@ def plot(self, **kwargs) -> Axes:
**kwargs : Dict
Supported: 'ax', 'color_flow', 'color_control'
"""

assert self.df is not None
kwargs = kwargs.copy() # Avoid side-effects
ax = kwargs.get("ax", None)
Expand Down
5 changes: 0 additions & 5 deletions python/ribasim/ribasim/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ def write(self, filepath: str | PathLike[str]) -> Path:
filepath : str | PathLike[str]
A file path with .toml extension.
"""

if self.use_validation:
self._validate_model()

Expand Down Expand Up @@ -351,7 +350,6 @@ def _has_valid_neighbor_amount(
nodes,
) -> bool:
"""Check if the neighbor amount of the two nodes connected by the given edge meet the minimum requirements."""

is_valid = True

# filter graph by edge type
Expand Down Expand Up @@ -419,7 +417,6 @@ def _add_source_sink_node(
Specify that their occurrence in from_node table or to_node table is 0.
"""

# loop over nodes, add the one that is not the downstream (from) or upstream (to) of any other nodes
for index, node in enumerate(nodes):
if nodes.index[index] not in node_info[f"{direction}_node_id"].to_numpy():
Expand Down Expand Up @@ -463,7 +460,6 @@ def _reset_contextvar(self) -> "Model":

def plot_control_listen(self, ax):
"""Plot the implicit listen edges of the model."""

df_listen_edge = pd.DataFrame(
data={
"control_node_id": pd.Series([], dtype="int32[pyarrow]"),
Expand Down Expand Up @@ -598,7 +594,6 @@ def to_xugrid(self, add_flow: bool = False, add_allocation: bool = False):
add_allocation : bool
add allocation results (Optional, defaults to False)
"""

if add_flow and add_allocation:
raise ValueError("Cannot add both allocation and flow results.")

Expand Down
3 changes: 2 additions & 1 deletion python/ribasim/ribasim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __getattr__(

def _node_lookup_numpy(node_id) -> Series[Int32]:
"""Create a lookup table from from node_id to the node dimension index.
Used when adding data onto the nodes of an xugrid dataset.
"""
return pd.Series(
Expand All @@ -43,6 +44,7 @@ def _node_lookup_numpy(node_id) -> Series[Int32]:

def _node_lookup(uds) -> Series[Int32]:
"""Create a lookup table from from node_id to the node dimension index.
Used when adding data onto the nodes of an xugrid dataset.
"""
return pd.Series(
Expand All @@ -57,7 +59,6 @@ def _edge_lookup(uds) -> Series[Int32]:
Used when adding data onto the edges of an xugrid dataset.
"""

return pd.Series(
index=uds["edge_id"],
data=uds[uds.grid.edge_dimension],
Expand Down
5 changes: 3 additions & 2 deletions python/ribasim_api/tests/test_bmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ def test_get_value_ptr_allocation(libribasim, user_demand, tmp_path):

def test_err_unknown_var(libribasim, basic, tmp_path):
"""
Unknown or invalid variable address should trigger Python Exception,
print the kernel error, and not crash the library
Unknown or invalid variable address.
Should trigger Python Exception, print the kernel error, and not crash the library.
"""
basic.write(tmp_path / "ribasim.toml")
config_file = str(tmp_path / "ribasim.toml")
Expand Down
18 changes: 3 additions & 15 deletions python/ribasim_testmodels/ribasim_testmodels/allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

def user_demand_model() -> Model:
"""Create a UserDemand test model with static and dynamic UserDemand on the same basin."""

model = Model(
starttime="2020-01-01",
endtime="2021-01-01",
Expand Down Expand Up @@ -90,9 +89,9 @@ def user_demand_model() -> Model:

def subnetwork_model() -> Model:
"""Create a UserDemand testmodel representing a subnetwork.
This model is merged into main_network_with_subnetworks_model.
"""

model = Model(
starttime="2020-01-01",
endtime="2020-04-01",
Expand Down Expand Up @@ -175,9 +174,9 @@ def subnetwork_model() -> Model:

def looped_subnetwork_model() -> Model:
"""Create a UserDemand testmodel representing a subnetwork containing a loop in the topology.
This model is merged into main_network_with_subnetworks_model.
"""

model = Model(
starttime="2020-01-01",
endtime="2021-01-01",
Expand Down Expand Up @@ -304,7 +303,6 @@ def looped_subnetwork_model() -> Model:

def minimal_subnetwork_model() -> Model:
"""Create a subnetwork that is minimal with non-trivial allocation."""

model = Model(
starttime="2020-01-01",
endtime="2021-01-01",
Expand Down Expand Up @@ -361,7 +359,6 @@ def minimal_subnetwork_model() -> Model:

def allocation_example_model() -> Model:
"""Generate a model that is used as an example of allocation in the docs."""

model = Model(
starttime="2020-01-01",
endtime="2020-01-20",
Expand Down Expand Up @@ -424,7 +421,6 @@ def allocation_example_model() -> Model:

def main_network_with_subnetworks_model() -> Model:
"""Generate a model which consists of a main network and multiple connected subnetworks."""

model = Model(
starttime="2020-01-01",
endtime="2020-03-01",
Expand Down Expand Up @@ -701,7 +697,6 @@ def main_network_with_subnetworks_model() -> Model:

def subnetworks_with_sources_model() -> Model:
"""Generate a model with subnetworks which contain sources."""

model = main_network_with_subnetworks_model()

model.flow_boundary.add(
Expand All @@ -721,7 +716,6 @@ def subnetworks_with_sources_model() -> Model:

def level_demand_model() -> Model:
"""Small model with LevelDemand nodes."""

model = Model(
starttime="2020-01-01",
endtime="2020-02-01",
Expand Down Expand Up @@ -782,7 +776,6 @@ def level_demand_model() -> Model:

def flow_demand_model() -> Model:
"""Small model with a FlowDemand."""

model = Model(
starttime="2020-01-01 00:00:00",
endtime="2021-01-01 00:00:00",
Expand Down Expand Up @@ -858,7 +851,6 @@ def flow_demand_model() -> Model:

def linear_resistance_demand_model():
"""Small model with a FlowDemand for a node with a max flow rate."""

model = Model(
starttime="2020-01-01 00:00:00",
endtime="2021-01-01 00:00:00",
Expand Down Expand Up @@ -893,11 +885,7 @@ def linear_resistance_demand_model():


def fair_distribution_model():
"""
Small model with little restrictions within the graph to see the behavior of
allocation in that case.
"""

"""See the behavior of allocation with few restrictions within the graph."""
model = Model(
starttime="2020-01-01 00:00:00",
endtime="2020-01-07 00:00:00",
Expand Down
3 changes: 1 addition & 2 deletions python/ribasim_testmodels/ribasim_testmodels/backwater.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@


def backwater_model():
"""Backwater curve as an integration test for ManningResistance"""

"""Backwater curve as an integration test for ManningResistance."""
node_type = np.full(102, "ManningResistance")
node_type[1::2] = "Basin"
node_type[0] = "FlowBoundary"
Expand Down
5 changes: 2 additions & 3 deletions python/ribasim_testmodels/ribasim_testmodels/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ def basic_arrow_model() -> ribasim.Model:


def basic_transient_model() -> ribasim.Model:
"""Update the basic model with transient forcing"""

"""Update the basic model with transient forcing."""
model = basic_model()
time = pd.date_range(model.starttime, model.endtime)
day_of_year = time.day_of_year.to_numpy()
Expand Down Expand Up @@ -265,11 +264,11 @@ def basic_transient_model() -> ribasim.Model:
def tabulated_rating_curve_model() -> ribasim.Model:
"""
Set up a model where the upstream Basin has two TabulatedRatingCurve attached.
They both flow to the same downstream Basin, but one has a static rating curve,
and the other one a time-varying rating curve.
Only the upstream Basin receives a (constant) precipitation.
"""

# Setup a model:
model = ribasim.Model(
starttime="2020-01-01",
Expand Down
2 changes: 0 additions & 2 deletions python/ribasim_testmodels/ribasim_testmodels/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

def bucket_model() -> ribasim.Model:
"""Bucket model with just a single basin at Deltares' headquarter."""

model = ribasim.Model(
starttime="2020-01-01",
endtime="2021-01-01",
Expand Down Expand Up @@ -38,7 +37,6 @@ def bucket_model() -> ribasim.Model:

def leaky_bucket_model() -> ribasim.Model:
"""Bucket model with dynamic forcing with missings at Deltares' headquarter."""

model = ribasim.Model(
starttime="2020-01-01",
endtime="2020-01-05",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

def outlet_continuous_control_model() -> Model:
"""Set up a small model that distributes flow over 2 branches."""

model = Model(
starttime="2020-01-01",
endtime="2021-01-01",
Expand Down
Loading

0 comments on commit 7d8e7a4

Please sign in to comment.