Skip to content

Commit 408e2ba

Browse files
committed
merge main
2 parents d6a4072 + 71e5014 commit 408e2ba

File tree

14 files changed

+662
-588
lines changed

14 files changed

+662
-588
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
strategy:
88
fail-fast: false
99
matrix:
10-
python-version: ["3.9", "3.11", "3.12"]
10+
python-version: ["3.9", "3.11", "3.12", "3.13"]
1111
os: [ubuntu-latest, windows-latest, macos-13]
1212
runs-on: ${{ matrix.os }}
1313
steps:
@@ -23,7 +23,7 @@ jobs:
2323
- name: Run image
2424
uses: abatilo/[email protected]
2525
with:
26-
poetry-version: 1.8.3
26+
poetry-version: 1.8.4
2727
- name: Cache Poetry virtualenv
2828
uses: actions/cache@v4
2929
id: cache
@@ -49,7 +49,7 @@ jobs:
4949
run: poetry run pytest --cov . --cov-report xml:coverage-reports/coverage-hydrolib-core.xml --junitxml=xunit-reports/xunit-result-hydrolib-core.xml
5050

5151
- name: Autoformat code if the check fails
52-
if: ${{ (matrix.os == 'ubuntu-latest') && (matrix.python-version == 3.12) }}
52+
if: ${{ (matrix.os == 'ubuntu-latest') && (matrix.python-version == 3.13) }}
5353
run: |
5454
poetry run isort .
5555
poetry run black .

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ jobs:
1212
fetch-depth: 0
1313
- uses: actions/setup-python@v5
1414
with:
15-
python-version: 3.12
15+
python-version: 3.13
1616

1717
- name: Run image
1818
uses: abatilo/[email protected]
1919
with:
20-
poetry-version: 1.8.3
20+
poetry-version: 1.8.4
2121
- name: Cache Poetry virtualenv
2222
uses: actions/cache@v4
2323
id: cache

.github/workflows/docs_release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ jobs:
1313
fetch-depth: 0
1414
- uses: actions/setup-python@v5
1515
with:
16-
python-version: 3.12
16+
python-version: 3.13
1717

1818
- name: Run image
1919
uses: abatilo/[email protected]
2020
with:
21-
poetry-version: 1.8.3
21+
poetry-version: 1.8.4
2222
- name: Cache Poetry virtualenv
2323
uses: actions/cache@v4
2424
id: cache

.github/workflows/integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
python-version: [3.12]
16+
python-version: [3.13]
1717
os: [ubuntu-latest]
1818
runs-on: ${{ matrix.os }}
1919
steps:
@@ -29,7 +29,7 @@ jobs:
2929
- name: Run image
3030
uses: abatilo/[email protected]
3131
with:
32-
poetry-version: 1.8.3
32+
poetry-version: 1.8.4
3333

3434
- name: Cache Poetry virtualenv
3535
uses: actions/cache@v4

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ jobs:
3636
- name: Set up python
3737
uses: actions/setup-python@v5
3838
with:
39-
python-version: 3.12
39+
python-version: 3.13
4040

4141
- name: Run image
4242
uses: abatilo/[email protected]
4343
with:
44-
poetry-version: 1.8.3
44+
poetry-version: 1.8.4
4545

4646
- name: Cache Poetry virtualenv
4747
uses: actions/cache@v4

hydrolib/core/dflowfm/tim/models.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from hydrolib.core.basemodel import BaseModel, ModelSaveSettings, ParsableFileModel
99
from hydrolib.core.dflowfm.tim.parser import TimParser
1010
from hydrolib.core.dflowfm.tim.serializer import TimSerializer, TimSerializerConfig
11+
from hydrolib.core.utils import FortranUtils
1112

1213

1314
class TimRecord(BaseModel):
@@ -161,6 +162,26 @@ def _get_serializer(
161162
def _get_parser(cls) -> Callable[[Path], Dict]:
162163
return TimParser.parse
163164

165+
@validator("timeseries", pre=True, check_fields=True, allow_reuse=True)
166+
def replace_fortran_scientific_notation_for_floats(cls, value, field):
167+
for record in value:
168+
if isinstance(record, dict):
169+
record["time"] = FortranUtils.replace_fortran_scientific_notation(
170+
record["time"]
171+
)
172+
record["data"] = FortranUtils.replace_fortran_scientific_notation(
173+
record["data"]
174+
)
175+
elif isinstance(record, TimRecord):
176+
record.time = FortranUtils.replace_fortran_scientific_notation(
177+
record.time
178+
)
179+
record.data = FortranUtils.replace_fortran_scientific_notation(
180+
record.data
181+
)
182+
183+
return value
184+
164185
@validator("timeseries")
165186
@classmethod
166187
def _validate_timeseries_values(cls, v: List[TimRecord]) -> List[TimRecord]:

hydrolib/core/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from pathlib import Path
77
from typing import Any, Callable, List, Optional
88

9+
from pydantic import validator
10+
from pydantic.v1.fields import ModelField
911
from strenum import StrEnum
1012

1113

@@ -332,3 +334,23 @@ def _calculate_md5_checksum(filepath: Path) -> str:
332334
for chunk in iter(lambda: file.read(4096), b""):
333335
md5_hash.update(chunk)
334336
return md5_hash.hexdigest()
337+
338+
339+
class FortranUtils:
340+
"""Utility class for Fortran specific conventions."""
341+
342+
_scientific_exp_d_notation_regex = re.compile(
343+
r"([\d.]+)([dD])([+-]?\d{1,3})"
344+
) # matches a float: 1d9, 1D-3, 1.D+4, etc.
345+
346+
@staticmethod
347+
def replace_fortran_scientific_notation(value):
348+
"""Replace Fortran scientific notation ("D" in exponent) with standard
349+
scientific notation ("e" in exponent).
350+
"""
351+
if isinstance(value, str):
352+
return FortranUtils._scientific_exp_d_notation_regex.sub(r"\1e\3", value)
353+
elif isinstance(value, list):
354+
return list(map(FortranUtils.replace_fortran_scientific_notation, value))
355+
356+
return value

mkdocs.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ theme:
2222
- navigation.top
2323
plugins:
2424
- search
25-
- mkdocs-jupyter
2625
- autorefs
27-
- table-reader
26+
2827
- macros:
2928
module_name: docs/include/mkdocs-macros/main
29+
- table-reader
3030
- mkdocstrings:
3131
default_handler: python
3232
handlers:
@@ -41,18 +41,15 @@ plugins:
4141
selection:
4242
inherited_members: false
4343

44-
custom_templates: templates
45-
watch:
46-
- hydrolib/core
4744
markdown_extensions:
4845
- pymdownx.highlight
4946
- pymdownx.superfences
5047
- admonition
5148
- toc:
5249
permalink: true
5350
- pymdownx.emoji:
54-
emoji_index: !!python/name:materialx.emoji.twemoji
55-
emoji_generator: !!python/name:materialx.emoji.to_svg
51+
emoji_index: !!python/name:material.extensions.emoji.twemoji
52+
emoji_generator: !!python/name:material.extensions.emoji.to_svg
5653
repo_url: https://github.com/Deltares/hydrolib-core
5754
repo_name: deltares/hydrolib-core
5855
edit_uri: edit/main/docs/

0 commit comments

Comments
 (0)