Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure args are Cubed arrays in unify_chunks #9

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cubed_xarray/cubedmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import numpy as np

from tlz import partition

from xarray.core import utils
from xarray.core.parallelcompat import ChunkManagerEntrypoint
from xarray.core.pycompat import is_chunked_array, is_duck_dask_array
Expand Down Expand Up @@ -192,9 +194,17 @@ def unify_chunks(
*args: Any, # can't type this as mypy assumes args are all same type, but dask unify_chunks args alternate types
**kwargs,
) -> tuple[dict[str, T_NormalizedChunks], list["CubedArray"]]:
from cubed.array_api import asarray
from cubed.core import unify_chunks

return unify_chunks(*args, **kwargs)
# Ensure that args are Cubed arrays. Note that we do this here and not in Cubed, following
# https://numpy.org/neps/nep-0047-array-api-standard.html#the-asarray-asanyarray-pattern
arginds = [
(asarray(a) if ind is not None else a, ind) for a, ind in partition(2, args)
]
array_args = [item for pair in arginds for item in pair]

return unify_chunks(*array_args, **kwargs)

def store(
self,
Expand Down