Skip to content

Commit 4176d1f

Browse files
authored
Patch: Pandas 3.x Compatibility (#239)
* replace .values with .to_numpy() for consistent behavior * force cast to defaul time resolution * force cost columns to float type * bump pandas version * update changelog * bump version * fix bug in metrics failure
1 parent 80e4737 commit 4176d1f

6 files changed

Lines changed: 27 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# CHANGELOG
22

3+
## v0.13.3. - 8 April 2026
4+
5+
- Enable Pandas v3.
6+
- Replaces some instances of `pd.DataFrame.values` with `pd.DataFrame.to_numpy()` to avoid
7+
compatibility issues in Pandas 2.3.3 and Pandas 3+.
8+
- Cast the weather datetime index to "us" instead of "ns" to match updated Pandas 3 and Polars
9+
defaults.
10+
- Cost columns are forced to be float columns to ensure for Pandas dtypes compatibility.
11+
- Fixes a bug in `Metrics.vessel_crew_hours_at_sea` where equipment-wise aggregations fail at
12+
frequencies more granular than the project level.
13+
314
## v0.13.2 - 10 February 2026
415

516
- Temporarily prohibit Pandas 3.0 to resolve failing tests and integrations.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies = [
1414
"attrs>=24.1.0",
1515
"numpy>=1.21",
1616
"scipy>=1.8",
17-
"pandas>=2,<3",
17+
"pandas>=2",
1818
"polars>=1.33.1",
1919
"pyarrow>=10",
2020
"jupyterlab>=3",

wombat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
from wombat.core.library import create_library_structure, load_yaml
55

66

7-
__version__ = "0.13.2"
7+
__version__ = "0.13.3"

wombat/core/library.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def format_weather(weather: pd.DataFrame) -> pl.DataFrame:
330330
.with_row_index()
331331
.with_columns(
332332
[
333-
pl.col("datetime").cast(pl.Datetime).dt.cast_time_unit("ns"),
333+
pl.col("datetime").cast(pl.Datetime).dt.cast_time_unit("us"),
334334
(pl.col("datetime").dt.hour()).alias("hour"),
335335
]
336336
)

wombat/core/post_processor.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,16 @@ def _apply_inflation_rate(self, events: pd.DataFrame) -> pd.DataFrame:
382382
pd.DataFrame
383383
The events dataframe with costs adjusted for inflation.
384384
"""
385+
events = events.astype(dict.fromkeys(self._cost_columns, "float"))
386+
385387
adjusted_inflation = deepcopy(self.inflation_rate)
386388
years = events.year.unique()
387389
years.sort()
388390
for year in years:
389-
row_filter = events.year == year
390391
if year > years[0]:
391-
events.loc[row_filter, self._cost_columns] *= adjusted_inflation
392+
events.loc[events.year.eq(year), self._cost_columns] *= (
393+
adjusted_inflation
394+
)
392395
adjusted_inflation *= self.inflation_rate
393396

394397
return events
@@ -1022,15 +1025,15 @@ def vessel_crew_hours_at_sea(
10221025
return pd.DataFrame(at_sea.sum()[["duration"]]).T.rename(
10231026
columns={"duration": "Total Crew Hours at Sea"}
10241027
)
1025-
additional_cols = frequency.group_cols
1028+
time_cols = frequency.group_cols
10261029
total_hours = (
10271030
total_hours.drop(columns=frequency.drop_cols)
1028-
.groupby(group_cols)[["N"]]
1031+
.groupby(time_cols)[["N"]]
10291032
.sum()
10301033
)
10311034

1032-
columns = additional_cols + columns
1033-
group_cols.extend(additional_cols)
1035+
columns = time_cols + columns
1036+
group_cols.extend(time_cols)
10341037
at_sea = at_sea[group_cols + ["duration"]].groupby(group_cols).sum()
10351038
if by_equipment:
10361039
total = []
@@ -1043,7 +1046,7 @@ def vessel_crew_hours_at_sea(
10431046
total_hours = (
10441047
total_hours.reset_index()
10451048
.rename(columns={"N": "Total Crew Hours at Sea"})[columns]
1046-
.set_index(additional_cols)
1049+
.set_index(time_cols)
10471050
)
10481051
return total_hours
10491052

wombat/windfarm/windfarm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ def _create_graph_layout(self, windfarm_layout: str | pd.DataFrame) -> None:
165165
windfarm, dict(layout[["id", "type"]].values), name="type"
166166
)
167167

168-
self.turbine_id: np.ndarray = layout.loc[turbine_filter, "id"].values
169-
self.substation_id = layout.loc[substation_filter, "id"].values
170-
self.electrolyzer_id = layout.loc[electrolyzer_filter, "id"].values
168+
self.turbine_id: np.ndarray = layout.loc[turbine_filter, "id"].to_numpy()
169+
self.substation_id = layout.loc[substation_filter, "id"].to_numpy()
170+
self.electrolyzer_id = layout.loc[electrolyzer_filter, "id"].to_numpy()
171171

172172
for substation in self.substation_id:
173173
windfarm.nodes[substation]["connection"] = layout.loc[

0 commit comments

Comments
 (0)