Skip to content

zonal.apply() output .name is inconsistent across backends #2611

@brendancol

Description

@brendancol

Description

xrspatial.zonal.apply() returns a DataArray but never sets the result's .name, so the value of .name depends on which backend ran:

  • numpy and cupy: .name is None
  • dask+numpy and dask+cupy: .name is an internal dask task name such as _chunk_fn-3e337fb640ced2398a1cced35ab359af

The dask name is a graph-task hash, so it is non-deterministic between runs too.

Every other DataArray-returning function in zonal.py sets a deterministic name and exposes a name= parameter: regions -> 'regions', hypsometric_integral -> 'hypsometric_integral', trim -> 'trim', crop -> 'crop'. apply() is the odd one out.

A pipeline that chains apply(...) into .to_dataset(), or otherwise relies on .name, gets a different (and on dask, meaningless) result depending on the backend.

Expected behavior

apply() should set a stable .name on its output and accept a name parameter, matching the rest of the zonal functions.

Proposed fix

Add a name parameter to apply() (default None) and pass it to the returned xr.DataArray. This makes .name deterministic and identical across all four backends.

Backends affected

numpy, cupy, dask+numpy, dask+cupy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiAPI design and consistencybugSomething isn't workingzonal tools

    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