Skip to content

Hooks for XArray operations #1938

Open
Open
@hameerabbasi

Description

@hameerabbasi

In hope of cleaner dask and sparse support (pydata/sparse#1), I wanted to suggest hooks for XArray operations.

Something like the following:

try:
    import dask.array as da
    xarray.hooks.register('nansum', da.array, da.nansum)
    ...
except ImportError:
    pass


try:
    import sparse.SparseArray
    xarray.hooks.register('nansum', sparse.SparseArray, sparse.nansum)
    ...
except ImportError:
    pass

Functions would work something like the following:
(the register would fall back to Numpy if nothing is found)

  • Check type of first/primary argument.
  • Check register for function.
  • Call function

I would argue that this should be in Numpy, but it's a huge project to put it there.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions