Skip to content

Fix some dask tests #9321

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

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 11 additions & 7 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,10 @@ def counting_get(*args, **kwargs):

def test_duplicate_dims(self):
data = np.random.normal(size=(4, 4))
arr = DataArray(data, dims=("x", "x"))
chunked_array = arr.chunk({"x": 2})
with pytest.warns(UserWarning, match="Duplicate dimension"):
arr = DataArray(data, dims=("x", "x"))
with pytest.warns(UserWarning, match="Duplicate dimension"):
chunked_array = arr.chunk({"x": 2})
assert chunked_array.chunks == ((2, 2), (2, 2))
assert chunked_array.chunksizes == {"x": (2, 2)}

Expand Down Expand Up @@ -1364,7 +1366,8 @@ def test_map_blocks_ds_transformations(func, map_ds):
@pytest.mark.parametrize("obj", [make_da(), make_ds()])
def test_map_blocks_da_ds_with_template(obj):
func = lambda x: x.isel(x=[1])
template = obj.isel(x=[1, 5, 9])
# a simple .isel(x=[1, 5, 9]) puts all those in a single chunk.
template = xr.concat([obj.isel(x=[i]) for i in [1, 5, 9]], dim="x")
with raise_if_dask_computes():
actual = xr.map_blocks(func, obj, template=template)
assert_identical(actual, template)
Expand Down Expand Up @@ -1395,15 +1398,16 @@ def test_map_blocks_roundtrip_string_index():

def test_map_blocks_template_convert_object():
da = make_da()
ds = da.to_dataset()

func = lambda x: x.to_dataset().isel(x=[1])
template = da.to_dataset().isel(x=[1, 5, 9])
template = xr.concat([da.to_dataset().isel(x=[i]) for i in [1, 5, 9]], dim="x")
with raise_if_dask_computes():
actual = xr.map_blocks(func, da, template=template)
assert_identical(actual, template)

ds = da.to_dataset()
func = lambda x: x.to_dataarray().isel(x=[1])
template = ds.to_dataarray().isel(x=[1, 5, 9])
template = xr.concat([ds.to_dataarray().isel(x=[i]) for i in [1, 5, 9]], dim="x")
with raise_if_dask_computes():
actual = xr.map_blocks(func, ds, template=template)
assert_identical(actual, template)
Expand All @@ -1429,7 +1433,7 @@ def test_map_blocks_errors_bad_template(obj):
xr.map_blocks(
lambda a: a.isel(x=[1]).assign_coords(x=[120]), # assign bad index values
obj,
template=obj.isel(x=[1, 5, 9]),
template=xr.concat([obj.isel(x=[i]) for i in [1, 5, 9]], dim="x"),
).compute()


Expand Down
11 changes: 5 additions & 6 deletions xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,11 @@ def test_datetime64_valid_range(self):
with pytest.raises(pderror, match=r"Out of bounds nanosecond"):
self.cls(["t"], [data])

@pytest.mark.xfail(reason="pandas issue 36615")
@pytest.mark.filterwarnings("ignore:Converting non-nanosecond")
def test_timedelta64_valid_range(self):
data = np.timedelta64("200000", "D")
pderror = pd.errors.OutOfBoundsTimedelta
with pytest.raises(pderror, match=r"Out of bounds nanosecond"):
with pytest.raises(pderror, match=r"Cannot convert"):
self.cls(["t"], [data])

def test_pandas_data(self):
Expand Down Expand Up @@ -2301,20 +2300,20 @@ def test_chunk(self):
assert blocked.chunks == ((3,), (3, 1))
assert blocked.data.name != first_dask_name

@pytest.mark.xfail
@pytest.mark.skip
def test_0d_object_array_with_list(self):
super().test_0d_object_array_with_list()

@pytest.mark.xfail
@pytest.mark.skip
def test_array_interface(self):
# dask array does not have `argsort`
super().test_array_interface()

@pytest.mark.xfail
@pytest.mark.skip
def test_copy_index(self):
super().test_copy_index()

@pytest.mark.xfail
@pytest.mark.skip
@pytest.mark.filterwarnings("ignore:elementwise comparison failed.*:FutureWarning")
def test_eq_all_dtypes(self):
super().test_eq_all_dtypes()
Expand Down
Loading