Skip to content

Commit a58c352

Browse files
sunt05claude
andcommitted
refactor: deprecate util.read_forcing in favour of OOP interface
- Add deprecation warning to util.read_forcing() pointing users to SUEWSForcing.from_file() - Extract internal _read_forcing_impl() for use by SUEWSForcing without triggering deprecation warnings - Update SUEWSForcing.from_file/from_files to use internal function This completes the deprecation of the functional API in favour of the modern OOP interface. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent cfe8360 commit a58c352

File tree

2 files changed

+43
-22
lines changed

2 files changed

+43
-22
lines changed

src/supy/suews_forcing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,13 @@ def from_file(cls, path: Union[str, Path], tstep_mod: int = 300) -> "SUEWSForcin
205205
SUEWSForcing
206206
Loaded forcing data
207207
"""
208-
from .util._io import read_forcing
208+
from .util._io import _read_forcing_impl
209209

210210
path = Path(path).expanduser().resolve()
211211
if not path.exists():
212212
raise FileNotFoundError(f"Forcing file not found: {path}")
213213

214-
df = read_forcing(str(path), tstep_mod=tstep_mod)
214+
df = _read_forcing_impl(str(path), tstep_mod=tstep_mod)
215215
return cls(df, source=str(path))
216216

217217
@classmethod
@@ -233,7 +233,7 @@ def from_files(
233233
SUEWSForcing
234234
Concatenated forcing data
235235
"""
236-
from .util._io import read_forcing
236+
from .util._io import _read_forcing_impl
237237

238238
if not paths:
239239
raise ValueError("Empty forcing file list provided")
@@ -243,7 +243,7 @@ def from_files(
243243
path = Path(p).expanduser().resolve()
244244
if not path.exists():
245245
raise FileNotFoundError(f"Forcing file not found: {path}")
246-
df = read_forcing(str(path), tstep_mod=tstep_mod)
246+
df = _read_forcing_impl(str(path), tstep_mod=tstep_mod)
247247
dfs.append(df)
248248

249249
combined = pd.concat(dfs, axis=0).sort_index()

src/supy/util/_io.py

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import warnings
2+
13
import numpy as np
24
from pathlib import Path
35
import pandas as pd
@@ -33,24 +35,8 @@ def read_suews(path_suews_file: str) -> pd.DataFrame:
3335
return df_suews
3436

3537

36-
def read_forcing(path_suews_file: str, tstep_mod=300) -> pd.DataFrame:
37-
"""read in SUEWS forcing files as DataFrame ready for SuPy simulation.
38-
39-
Parameters
40-
----------
41-
path_suews_file : str
42-
a string that represents wildcard pattern can locate SUEWS forcing files, which should follow `SUEWS convention <https://suews.readthedocs.io/en/latest/input_files/met_input.html>`_.
43-
44-
tstep_mod: int or None, optional
45-
time step [s] for resampling, by default 300.
46-
If `None`, resampling will be skipped.
47-
48-
Returns
49-
-------
50-
pd.DataFrame
51-
datetime-aware DataFrame
52-
"""
53-
38+
def _read_forcing_impl(path_suews_file: str, tstep_mod=300) -> pd.DataFrame:
39+
"""Internal implementation of read_forcing (no deprecation warning)."""
5440
path_suews_file = Path(path_suews_file)
5541
path_input = path_suews_file.parent
5642
str_pattern = path_suews_file.name
@@ -73,3 +59,38 @@ def read_forcing(path_suews_file: str, tstep_mod=300) -> pd.DataFrame:
7359
df_forcing = from_nan(df_forcing)
7460

7561
return df_forcing
62+
63+
64+
def read_forcing(path_suews_file: str, tstep_mod=300) -> pd.DataFrame:
65+
"""Read in SUEWS forcing files as DataFrame ready for SuPy simulation.
66+
67+
.. deprecated::
68+
Use :class:`supy.SUEWSForcing.from_file` instead for the modern
69+
object-oriented interface with additional validation and analysis features.
70+
71+
Parameters
72+
----------
73+
path_suews_file : str
74+
a string that represents wildcard pattern can locate SUEWS forcing files,
75+
which should follow `SUEWS convention
76+
<https://suews.readthedocs.io/en/latest/input_files/met_input.html>`_.
77+
78+
tstep_mod: int or None, optional
79+
time step [s] for resampling, by default 300.
80+
If `None`, resampling will be skipped.
81+
82+
Returns
83+
-------
84+
pd.DataFrame
85+
datetime-aware DataFrame
86+
87+
See Also
88+
--------
89+
supy.SUEWSForcing.from_file : Modern OOP interface (recommended)
90+
"""
91+
warnings.warn(
92+
"supy.util.read_forcing is deprecated, use SUEWSForcing.from_file() instead",
93+
DeprecationWarning,
94+
stacklevel=2,
95+
)
96+
return _read_forcing_impl(path_suews_file, tstep_mod)

0 commit comments

Comments
 (0)