Skip to content

Commit 975dd75

Browse files
committed
Remove from_xarray_dataset_dict
1 parent d9ad51c commit 975dd75

2 files changed

Lines changed: 3 additions & 31 deletions

File tree

src/parcels/_datasets/utils.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import copy
21
from collections.abc import Hashable
32
from typing import Any, Literal, TypeVar
43

@@ -189,23 +188,6 @@ def verbose_print(*args, **kwargs):
189188
verbose_print("=" * 30 + " End of Comparison " + "=" * 30)
190189

191190

192-
def from_xarray_dataset_dict(d) -> xr.Dataset:
193-
"""Reconstruct a dataset with zero data from the output of ``xarray.Dataset.to_dict(data=False)``.
194-
195-
Useful in issues helping users debug fieldsets - sharing dataset schemas with associated metadata
196-
without sharing the data itself.
197-
198-
Example
199-
-------
200-
>>> import xarray as xr
201-
>>> from parcels._datasets.structured.generic import datasets
202-
>>> ds = datasets['ds_2d_left']
203-
>>> d = ds.to_dict(data=False)
204-
>>> ds2 = from_xarray_dataset_dict(d)
205-
"""
206-
return xr.Dataset.from_dict(_fill_with_dummy_data(copy.deepcopy(d)))
207-
208-
209191
def replace_arrays_with_zeros(
210192
ds: xr.Dataset, except_for: Literal["coords"] | list[Hashable] | None = None
211193
) -> xr.Dataset:

tests/datasets/test_utils.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@
66
from parcels._datasets.structured.generic import datasets
77

88

9-
def test_from_xarray_dataset_dict():
10-
ds_expected = datasets["ds_2d_left"]
11-
d = ds_expected.to_dict(data=False)
12-
ds = utils.from_xarray_dataset_dict(d)
13-
14-
assert list(ds.coords) == list(ds_expected.coords)
15-
assert list(ds.data_vars) == list(ds_expected.data_vars)
16-
17-
for k in set(ds.coords) | set(ds.data_vars):
18-
assert ds[k].attrs == ds_expected[k].attrs, f"Attrs for {k!r} do not match"
19-
20-
219
def _replace_with_cf_time(ds) -> xr.Dataset:
2210
import cftime
2311

@@ -52,11 +40,13 @@ def nonzero_ds():
5240
},
5341
)
5442

55-
@pytest.mark.parametrize("ds", [pytest.param(v, id=k) for k,v in datasets.items()])
43+
44+
@pytest.mark.parametrize("ds", [pytest.param(v, id=k) for k, v in datasets.items()])
5645
@pytest.mark.parametrize("except_for", [None, "coords"])
5746
def test_replace_arrays_with_zeros(ds, except_for):
5847
utils.replace_arrays_with_zeros(ds, except_for=except_for)
5948

49+
6050
def test_replace_arrays_with_zeros_none(nonzero_ds):
6151
"""except_for=None: all data_vars and coords replaced with zeros."""
6252
result = utils.replace_arrays_with_zeros(nonzero_ds, except_for=None)

0 commit comments

Comments
 (0)