-
Notifications
You must be signed in to change notification settings - Fork 280
/
test_hashing.py
40 lines (34 loc) · 1.38 KB
/
test_hashing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Copyright Iris contributors
#
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""Test array hashing in :mod:`iris._concatenate`."""
import dask.array as da
import numpy as np
import pytest
from iris import _concatenate
@pytest.mark.parametrize(
"a,b,eq",
[
(np.arange(2), da.arange(2), True),
(np.array([1], dtype=np.float32), np.array([1], dtype=bool), True),
(np.array([np.nan, 1.0]), np.array([np.nan, 1.0]), True),
(np.ma.array([1, 2], mask=[0, 1]), np.ma.array([1, 2], mask=[0, 1]), True),
(np.ma.array([1, 2], mask=[0, 1]), np.ma.array([1, 2], mask=[0, 0]), False),
(da.arange(6).reshape((2, 3)), da.arange(6, chunks=1).reshape((2, 3)), True),
(da.arange(20, chunks=1), da.arange(20, chunks=2), True),
(
da.ma.masked_array([1, 2], mask=[0, 1]),
da.ma.masked_array([1, 2], mask=[0, 1]),
True,
),
],
)
def test_compute_hashes(a, b, eq):
hashes = _concatenate._compute_hashes([a, b])
assert eq == (hashes[_concatenate.array_id(a)] == hashes[_concatenate.array_id(b)])
def test_arrayhash_incompatible_chunks_raises():
hash1 = _concatenate._ArrayHash(1, chunks=(1, 1))
hash2 = _concatenate._ArrayHash(1, chunks=(2,))
with pytest.raises(ValueError):
hash1 == hash2