Skip to content

Commit e2a2675

Browse files
committed
Using proper import of testing module instead of local
1 parent b79620a commit e2a2675

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

xarray/tests/test_duck_array_ops.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88
from numpy import array, nan
99

10-
from xarray import DataArray, Dataset, cftime_range, concat
10+
from xarray import DataArray, Dataset, cftime_range, concat, testing
1111
from xarray.core import dtypes, duck_array_ops
1212
from xarray.core.duck_array_ops import (
1313
array_notnull_equiv,
@@ -895,26 +895,44 @@ def test_push_dask():
895895
np.testing.assert_equal(actual, expected)
896896

897897

898-
@pytest.mark.parametrize("shape", [(200, 1), (10, 10, 2), (4, 50)])
898+
@pytest.mark.parametrize("shape", [(200), (10, 10, 2), (4, 50)])
899899
@pytest.mark.parametrize("tolerance", [1e-2, 1e-4, 1e-6])
900-
@pytest.mark.parametrize("dask", [False, True])
901-
def test_isin_tolerance(shape, tolerance, dask):
902-
if dask and not has_dask:
900+
@pytest.mark.parametrize("dask_for_A", [True, False])
901+
@pytest.mark.parametrize("dask_for_B", [True, False])
902+
def test_isin_tolerance(shape, tolerance, dask_for_A, dask_for_B):
903+
if (dask_for_A or dask_for_B) and not has_dask:
903904
pytest.skip("requires dask")
904905

905-
in_margin = tolerance / 2 # within acceptable margin
906+
in_margin = tolerance / 2 # measure within acceptable margin
906907
arrayA = np.arange(-10.0, 10.0, 0.1).reshape(shape)
907-
908908
expected = np.array([item % 2 == 0 for item in range(0, arrayA.size)]).reshape(
909909
shape
910910
)
911-
for offset_direction in [1, -1]:
912-
# generate test set
913-
arrayB = -99 * (~expected) + (in_margin + arrayA * expected)
914-
if dask:
915-
import dask.array
916-
917-
arrayB = dask.array.from_array(arrayB)
918-
919-
actual = isin_tolerance(arrayA, arrayB, tolerance)
920-
np.testing.assert_equal(actual, expected)
911+
if dask_for_A or dask_for_B: # tests including dask arrays
912+
import dask.array
913+
914+
if dask_for_A:
915+
arrayA = dask.array.from_array(arrayA)
916+
expected = dask.array.from_array(expected)
917+
for offset_direction in [1, -1]:
918+
# generate test set
919+
if dask_for_B:
920+
arrayB = dask.array.from_array(
921+
[-99 * (~expected) + (in_margin + arrayA * expected)]
922+
)
923+
else:
924+
arrayB = -99 * (~expected) + (in_margin + arrayA * expected)
925+
# test function
926+
actual = isin_tolerance(arrayA, arrayB, tolerance)
927+
928+
testing.assert_duckarray_equal(actual, expected)
929+
assert type(actual) == type(expected)
930+
else: # test only using numpy
931+
for offset_direction in [1, -1]:
932+
# generate test set
933+
arrayB = -99 * (~expected) + (in_margin + arrayA * expected)
934+
# test function
935+
actual = isin_tolerance(arrayA, arrayB, tolerance)
936+
937+
testing.assert_duckarray_equal(actual, expected)
938+
assert type(actual) == type(expected)

0 commit comments

Comments
 (0)