Skip to content

Commit db641dd

Browse files
authored
Merge pull request #341 from boutproject/ci-apt-update
Fix CI: apt update on runner, file lock race condition
2 parents bcccd23 + 194dee8 commit db641dd

6 files changed

Lines changed: 175 additions & 96 deletions

File tree

.github/workflows/master.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
- name: Install dependencies
3333
run: |
3434
python -m pip install --upgrade pip
35+
sudo apt-get update
3536
sudo apt-get -y install libhdf5-dev
3637
- name: Install package
3738
run: |
@@ -61,6 +62,7 @@ jobs:
6162
- name: Install dependencies
6263
run: |
6364
python -m pip install --upgrade pip
65+
sudo apt-get update
6466
sudo apt-get -y install libhdf5-dev
6567
pip install xarray~=2023.12.0 pandas~=2.2.0
6668
- name: Install package

.github/workflows/pythonpackage.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ jobs:
3232
- name: Install dependencies
3333
run: |
3434
python -m pip install --upgrade pip
35+
sudo apt-get update
3536
sudo apt-get -y install libhdf5-dev
3637
- name: Install package
3738
run: |
3839
pip install -e .[calc,tests] --no-binary h5netcdf --no-binary h5py
3940
pip install git+https://github.com/dschwoerer/xarray@netcdf4-locking-closing
4041
- name: Test with pytest
4142
run: |
42-
pytest -vv --long --cov
43+
timeout -s INT 90m pytest -vvv --long --cov --full-trace
4344
4445
4546
# test with oldest supported version of packages
@@ -61,6 +62,7 @@ jobs:
6162
- name: Install dependencies
6263
run: |
6364
python -m pip install --upgrade pip
65+
sudo apt-get update
6466
sudo apt-get -y install libhdf5-dev
6567
pip install xarray~=2023.12.0 pandas~=2.2.0
6668
- name: Install package

xbout/boutdataset.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .region import _from_region
3030
from .utils import (
3131
_add_cartesian_coordinates,
32+
_check_filetype,
3233
_get_bounding_surfaces,
3334
_split_into_restarts,
3435
)
@@ -719,8 +720,7 @@ def remove_yboundaries(self, **kwargs):
719720
new_metadata = variables[-1].metadata
720721
elif ycoord in self.data[v].dims:
721722
raise ValueError(
722-
f"{v} only has a {ycoord}-dimension so cannot split "
723-
f"into regions."
723+
f"{v} only has a {ycoord}-dimension so cannot split into regions."
724724
)
725725
else:
726726
variable = self.data[v]
@@ -788,6 +788,9 @@ def save(
788788
----------
789789
savepath : str, optional
790790
filetype : str, optional
791+
netCDF format passed to xarray. NOT THE SAME as "engine", which
792+
defaults to h5netcdf via ``_check_filetype()``.
793+
See https://docs.xarray.dev/en/latest/generated/xarray.Dataset.to_netcdf.html
791794
variables : list of str, optional
792795
Variables from the dataset to save. Default is to save all of them.
793796
separate_vars: bool, optional
@@ -910,6 +913,7 @@ def dict_to_attrs(obj, section):
910913
single_var_ds.to_netcdf(
911914
path=str(var_savepath),
912915
format=filetype,
916+
engine=_check_filetype(Path(var_savepath)),
913917
compute=True,
914918
encoding=var_encoding,
915919
)
@@ -923,7 +927,11 @@ def dict_to_attrs(obj, section):
923927
print("Saving data...")
924928
with ProgressBar():
925929
to_save.to_netcdf(
926-
path=savepath, format=filetype, compute=True, encoding=encoding
930+
path=savepath,
931+
engine=_check_filetype(Path(savepath)),
932+
format=filetype,
933+
compute=True,
934+
encoding=encoding,
927935
)
928936

929937
return
@@ -992,7 +1000,12 @@ def to_restart(
9921000
)
9931001

9941002
with ProgressBar():
995-
xr.save_mfdataset(restart_datasets, paths, compute=True)
1003+
xr.save_mfdataset(
1004+
restart_datasets,
1005+
paths,
1006+
compute=True,
1007+
engine=_check_filetype(paths[0]),
1008+
)
9961009

9971010
def animate_list(
9981011
self,

xbout/load.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,15 @@ def open_boutdataset(
197197
# xr.open_mfdataset only accepts glob patterns as
198198
# strings, not Path objects
199199
datapath = str(datapath)
200+
_, filetype = _expand_filepaths(datapath)
201+
reload_kwargs = dict(kwargs)
202+
reload_kwargs.setdefault("engine", file_engine or filetype)
200203
ds = xr.open_mfdataset(
201204
datapath,
202205
chunks=chunks,
203206
combine="by_coords",
204207
data_vars="minimal",
205-
**kwargs,
208+
**reload_kwargs,
206209
)
207210
elif input_type == "reload_fake":
208211
ds = xr.combine_by_coords(datapath, data_vars="minimal").chunk(chunks)

0 commit comments

Comments
 (0)