Skip to content

slope() leaks the dask graph token as .name on dask backends #2837

@brendancol

Description

@brendancol

On the dask backends, slope(agg, name=None) returns a DataArray whose .name is the dask array's internal graph token (e.g. _trim-<hash> for planar, getitem-<hash> for geodesic) instead of None. The numpy and cupy backends correctly return None.

The cause: when name=None is passed to xr.DataArray(dask_array, name=None, ...), xarray adopts the dask array's name rather than leaving it unset. So the public .name ends up backend-dependent and non-deterministic per call.

This is the same class of bug already fixed for zonal (#2611), focal (#2733), and proximity (#2723).

Reproduce

import numpy as np, xarray as xr, dask.array as da
from xrspatial import slope

arr = xr.DataArray(da.from_array(np.random.rand(8, 8), chunks=4),
                   dims=['y', 'x'],
                   coords={'y': np.arange(8), 'x': np.arange(8)})
print(slope(arr).name)   # -> '_trim-...' ; expected: None

Fix

Reset result.name after construction so all four backends agree (None when name=None, the given name otherwise). Regression tests assert name consistency across numpy/cupy/dask+numpy/dask+cupy for both planar and geodesic methods.

Found by a metadata sweep of the slope module.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions