2
2
import pickle
3
3
import sys
4
4
from contextlib import suppress
5
- from distutils .version import LooseVersion
6
5
from textwrap import dedent
7
6
8
7
import numpy as np
13
12
import xarray .ufuncs as xu
14
13
from xarray import DataArray , Dataset , Variable
15
14
from xarray .core import duck_array_ops
15
+ from xarray .core .pycompat import dask_version
16
16
from xarray .testing import assert_chunks_equal
17
17
from xarray .tests import mock
18
18
@@ -111,10 +111,7 @@ def test_indexing(self):
111
111
self .assertLazyAndIdentical (u [:1 ], v [:1 ])
112
112
self .assertLazyAndIdentical (u [[0 , 1 ], [0 , 1 , 2 ]], v [[0 , 1 ], [0 , 1 , 2 ]])
113
113
114
- @pytest .mark .skipif (
115
- LooseVersion (dask .__version__ ) < LooseVersion ("2021.04.1" ),
116
- reason = "Requires dask v2021.04.1 or later" ,
117
- )
114
+ @pytest .mark .skipif (dask_version < "2021.04.1" , reason = "Requires dask >= 2021.04.1" )
118
115
@pytest .mark .parametrize (
119
116
"expected_data, index" ,
120
117
[
@@ -133,10 +130,7 @@ def test_setitem_dask_array(self, expected_data, index):
133
130
arr [index ] = 99
134
131
assert_identical (arr , expected )
135
132
136
- @pytest .mark .skipif (
137
- LooseVersion (dask .__version__ ) >= LooseVersion ("2021.04.1" ),
138
- reason = "Requires dask v2021.04.0 or earlier" ,
139
- )
133
+ @pytest .mark .skipif (dask_version >= "2021.04.1" , reason = "Requires dask < 2021.04.1" )
140
134
def test_setitem_dask_array_error (self ):
141
135
with pytest .raises (TypeError , match = r"stored in a dask array" ):
142
136
v = self .lazy_var
@@ -612,25 +606,6 @@ def test_dot(self):
612
606
lazy = self .lazy_array .dot (self .lazy_array [0 ])
613
607
self .assertLazyAndAllClose (eager , lazy )
614
608
615
- @pytest .mark .skipif (LooseVersion (dask .__version__ ) >= "2.0" , reason = "no meta" )
616
- def test_dataarray_repr_legacy (self ):
617
- data = build_dask_array ("data" )
618
- nonindex_coord = build_dask_array ("coord" )
619
- a = DataArray (data , dims = ["x" ], coords = {"y" : ("x" , nonindex_coord )})
620
- expected = dedent (
621
- """\
622
- <xarray.DataArray 'data' (x: 1)>
623
- {!r}
624
- Coordinates:
625
- y (x) int64 dask.array<chunksize=(1,), meta=np.ndarray>
626
- Dimensions without coordinates: x""" .format (
627
- data
628
- )
629
- )
630
- assert expected == repr (a )
631
- assert kernel_call_count == 0 # should not evaluate dask array
632
-
633
- @pytest .mark .skipif (LooseVersion (dask .__version__ ) < "2.0" , reason = "needs meta" )
634
609
def test_dataarray_repr (self ):
635
610
data = build_dask_array ("data" )
636
611
nonindex_coord = build_dask_array ("coord" )
@@ -648,7 +623,6 @@ def test_dataarray_repr(self):
648
623
assert expected == repr (a )
649
624
assert kernel_call_count == 0 # should not evaluate dask array
650
625
651
- @pytest .mark .skipif (LooseVersion (dask .__version__ ) < "2.0" , reason = "needs meta" )
652
626
def test_dataset_repr (self ):
653
627
data = build_dask_array ("data" )
654
628
nonindex_coord = build_dask_array ("coord" )
@@ -1645,7 +1619,7 @@ def test_optimize():
1645
1619
1646
1620
# The graph_manipulation module is in dask since 2021.2 but it became usable with
1647
1621
# xarray only since 2021.3
1648
- @pytest .mark .skipif (LooseVersion ( dask . __version__ ) <= "2021.02.0" , reason = "new module" )
1622
+ @pytest .mark .skipif (dask_version <= "2021.02.0" , reason = "new module" )
1649
1623
def test_graph_manipulation ():
1650
1624
"""dask.graph_manipulation passes an optional parameter, "rename", to the rebuilder
1651
1625
function returned by __dask_postperist__; also, the dsk passed to the rebuilder is
0 commit comments