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

Skipping variables in datasets that don't have the core dim #2674

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ def apply_dict_of_variables_ufunc(func, *args, **kwargs):

result_vars = OrderedDict()
for name, variable_args in zip(names, grouped_by_name):
if len(variable_args) == 1 and signature.all_input_core_dims:
variable_arg, = variable_args
if not set(variable_arg.dims) & signature.all_core_dims:
result_vars[name] = variable_arg
continue
result_vars[name] = func(*variable_args)

if signature.num_outputs > 1:
Expand Down
12 changes: 12 additions & 0 deletions xarray/tests/test_computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pickle
from collections import OrderedDict
from distutils.version import LooseVersion
from functools import partial

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -850,6 +851,17 @@ def apply_truncate_x_x_valid(obj):
apply_truncate_x_x_valid(dataset))


def test_ignore_variables_without_dim():

ds = xr.Dataset(dict(
a=xr.DataArray(np.random.rand(2, 3), dims=list('xy')),
b=xr.DataArray(np.random.rand(3, 4), dims=list('yz'))
))
result = apply_ufunc(partial(np.nansum, axis=-1),
ds, input_core_dims=[['x']])
assert set(result.dims) == set('yz')


@pytest.mark.parametrize('use_dask', [True, False])
def test_dot(use_dask):
if use_dask:
Expand Down