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

dask: fix Data.equals for arbitrary chunk distributions #330

Merged
merged 2 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion cf/data/dask_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import dask.array as da
import numpy as np
from dask.core import flatten

from ..cfdatetime import dt2rt, rt2dt
from ..functions import atol as cf_atol
Expand Down Expand Up @@ -83,7 +84,13 @@ def allclose(a_blocks, b_blocks, rtol=rtol, atol=atol):
if not isinstance(b_blocks, list):
b_blocks = (b_blocks,)

for a, b in zip(a_blocks, b_blocks):
# Note: If a_blocks or b_blocks has more than one chunk in
# more than one dimension they will comprise a nested
# sequence of sequences, that needs to be flatten so
davidhassell marked this conversation as resolved.
Show resolved Hide resolved
# that we can safely iterate through the actual numpy
# array elements.

for a, b in zip(flatten(a_blocks), flatten(b_blocks)):
result &= np.ma.allclose(
a,
b,
Expand Down
7 changes: 7 additions & 0 deletions cf/test/test_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@ def test_Data_equals(self):
# Test ignore_data_type parameter
self.assertTrue(d2.equals(d, ignore_data_type=True))

# Test all possible chunk combinations
for j, i in itertools.product([1, 2], [1, 2, 3]):
d = cf.Data(np.arange(6).reshape(2, 3), "m", chunks=(j, i))
for j, i in itertools.product([1, 2], [1, 2, 3]):
e = cf.Data(np.arange(6).reshape(2, 3), "m", chunks=(j, i))
self.assertTrue(d.equals(e))

@unittest.skipIf(TEST_DASKIFIED_ONLY, "hits unexpected kwarg 'ndim'")
def test_Data_halo(self):
if self.test_only and inspect.stack()[0][3] not in self.test_only:
Expand Down