-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle kwargs better in store * Add a test * Only run with processes executor on Python 3.11 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0b35a57
commit 495bcf3
Showing
3 changed files
with
70 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
from importlib.metadata import version | ||
|
||
|
||
try: | ||
__version__ = version("cubed-xarray") | ||
except Exception: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,63 @@ | ||
import sys | ||
|
||
import cubed | ||
import pytest | ||
import xarray as xr | ||
from cubed.runtime.create import create_executor | ||
from xarray.namedarray.parallelcompat import list_chunkmanagers | ||
import cubed | ||
from xarray.tests import assert_allclose, create_test_data | ||
|
||
from cubed_xarray.cubedmanager import CubedManager | ||
|
||
EXECUTORS = [create_executor("single-threaded")] | ||
|
||
if sys.version_info >= (3, 11): | ||
EXECUTORS.append(create_executor("processes")) | ||
|
||
|
||
@pytest.fixture( | ||
scope="module", | ||
params=EXECUTORS, | ||
ids=[executor.name for executor in EXECUTORS], | ||
) | ||
def executor(request): | ||
return request.param | ||
|
||
|
||
class TestDiscoverCubedManager: | ||
def test_list_cubedmanager(self): | ||
chunkmanagers = list_chunkmanagers() | ||
assert 'cubed' in chunkmanagers | ||
assert isinstance(chunkmanagers['cubed'], CubedManager) | ||
assert "cubed" in chunkmanagers | ||
assert isinstance(chunkmanagers["cubed"], CubedManager) | ||
|
||
def test_chunk(self): | ||
da = xr.DataArray([1, 2], dims='x') | ||
chunked = da.chunk(x=1, chunked_array_type='cubed') | ||
da = xr.DataArray([1, 2], dims="x") | ||
chunked = da.chunk(x=1, chunked_array_type="cubed") | ||
assert isinstance(chunked.data, cubed.Array) | ||
assert chunked.chunksizes == {'x': (1, 1)} | ||
assert chunked.chunksizes == {"x": (1, 1)} | ||
|
||
# TODO test cubed is default when dask not installed | ||
|
||
# TODO test dask is default over cubed when both installed | ||
|
||
|
||
def test_to_zarr(tmpdir, executor): | ||
spec = cubed.Spec(allowed_mem="200MB", executor=executor) | ||
|
||
original = create_test_data().chunk( | ||
chunked_array_type="cubed", from_array_kwargs={"spec": spec} | ||
) | ||
|
||
filename = tmpdir / "out.zarr" | ||
original.to_zarr(filename) | ||
|
||
with xr.open_dataset( | ||
filename, | ||
chunks="auto", | ||
engine="zarr", | ||
chunked_array_type="cubed", | ||
from_array_kwargs={"spec": spec}, | ||
) as restored: | ||
assert isinstance(restored.var1.data, cubed.Array) | ||
computed = restored.compute() | ||
assert_allclose(original, computed) |