Skip to content

Commit

Permalink
Sort DataFrames inplace.
Browse files Browse the repository at this point in the history
  • Loading branch information
evetion committed Sep 14, 2023
1 parent 9ae0a1f commit 2c065b9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
rev: v0.0.286
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
args: [--fix, --exit-non-zero-on-fix, --ignore=PD002]
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion python/ribasim/ribasim/input_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,5 @@ def sort(self):
if dataframe is None:
continue
else:
dataframe = dataframe.sort_values("node_id", ignore_index=True)
dataframe.sort_values("node_id", ignore_index=True, inplace=True)
return
10 changes: 5 additions & 5 deletions python/ribasim/ribasim/node_types/basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ class Basin(TableModel):
state: Optional[DataFrame[StateSchema]] = None

def sort(self):
self.profile = self.profile.sort_values(["node_id", "level"], ignore_index=True)
self.profile.sort_values(["node_id", "level"], ignore_index=True, inplace=True)
if self.static is not None:
self.static = self.static.sort_values("node_id", ignore_index=True)
self.static.sort_values("node_id", ignore_index=True, inplace=True)
if self.forcing is not None:
self.forcing = self.forcing.sort_values(
["time", "node_id"], ignore_index=True
self.forcing.sort_values(
["time", "node_id"], ignore_index=True, inplace=True
)
if self.state is not None:
self.state = self.state.sort_values("node_id", ignore_index=True)
self.state.sort_values("node_id", ignore_index=True, inplace=True)
2 changes: 1 addition & 1 deletion python/ribasim/ribasim/node_types/fractional_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ class FractionalFlow(TableModel):
static: DataFrame[StaticSchema]

def sort(self):
self.static = self.static.sort_values("node_id", ignore_index=True)
self.static.sort_values("node_id", ignore_index=True, inplace=True)
9 changes: 6 additions & 3 deletions python/ribasim/ribasim/node_types/tabulated_rating_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ class TabulatedRatingCurve(TableModel):
time: Optional[DataFrame[TimeSchema]] = None

def sort(self):
self.static = self.static.sort_values(["node_id", "level"], ignore_index=True)
if self.static:
self.static.sort_values(
["node_id", "level"], ignore_index=True, inplace=True
)
if self.time is not None:
self.time = self.time.sort_values(
["time", "node_id", "level"], ignore_index=True
self.time.sort_values(
["time", "node_id", "level"], ignore_index=True, inplace=True
)

0 comments on commit 2c065b9

Please sign in to comment.