Skip to content

Dask error on xarray.corr #5715

@Gijom

Description

@Gijom

What happened:
When I use xarray.corr on two Dataarrays I get a NameError: name 'dask' is not defined error. Notice that dask is not installed in my environement.

What you expected to happen:
Obtain the correlation values without dask interfering (as it should be optional in my understanding)

Minimal Complete Verifiable Example:

N = 100
ds = xr.Dataset(
    data_vars={
        'x': ('t', np.random.randn(N)),
        'y': ('t', np.random.randn(N))
    },
    coords={
        't': range(N)
    }
)
xr.corr(ds['y'], ds['x'])

Results in:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/tmp/ipykernel_732567/1992585666.py in <module>
----> 1 xr.corr(ds['y'], ds['x'])

~/.local/share/virtualenvs/e-sport-ml-IJ_mJ64l/lib/python3.8/site-packages/xarray/core/computation.py in corr(da_a, da_b, dim)
   1343         )
   1344 
-> 1345     return _cov_corr(da_a, da_b, dim=dim, method="corr")
   1346 
   1347 

~/.local/share/virtualenvs/e-sport-ml-IJ_mJ64l/lib/python3.8/site-packages/xarray/core/computation.py in _cov_corr(da_a, da_b, dim, ddof, method)
   1371             return da
   1372 
-> 1373     da_a = da_a.map_blocks(_get_valid_values, args=[da_b])
   1374     da_b = da_b.map_blocks(_get_valid_values, args=[da_a])
   1375 

~/.local/share/virtualenvs/e-sport-ml-IJ_mJ64l/lib/python3.8/site-packages/xarray/core/dataarray.py in map_blocks(self, func, args, kwargs, template)
   3811         from .parallel import map_blocks
   3812 
-> 3813         return map_blocks(func, self, args, kwargs, template)
   3814 
   3815     def polyfit(

~/.local/share/virtualenvs/e-sport-ml-IJ_mJ64l/lib/python3.8/site-packages/xarray/core/parallel.py in map_blocks(func, obj, args, kwargs, template)
    332             )
    333 
--> 334     if not dask.is_dask_collection(obj):
    335         return func(obj, *args, **kwargs)
    336 

NameError: name 'dask' is not defined

Environment:

INSTALLED VERSIONS
------------------
commit: None
python: 3.8.6 (default, Dec 16 2020, 11:33:05) 
[GCC 10.2.0]
python-bits: 64
OS: Linux
OS-release: 5.13.6-arch1-1
machine: x86_64
processor: 
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.0
libnetcdf: None

xarray: 0.19.0
pandas: 1.3.1
numpy: 1.21.1
scipy: 1.7.1
netCDF4: None
pydap: None
h5netcdf: None
h5py: 3.3.0
Nio: None
zarr: None
cftime: None
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.4.2
cartopy: None
seaborn: 0.11.1
numbagg: None
pint: None
setuptools: 51.0.0
pip: 20.3.1
conda: None
pytest: None
IPython: 7.26.0
sphinx: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions