Skip to content

Improve XarrayLike types to consolidate xr.DataArray and xr.Dataset #830

@nikeethr

Description

@nikeethr

Is your feature request related to a problem? Please describe.

Having to deal with both xr.DataArray AND xr.Dataset leads to branching logic and additional tests all over the code.

Describe the solution you'd like

XarrayLike is a type that is accepted as input to most functions. I'd like to propose XarrayLike extended to unify the types, rather than just a static type check utilty. In essence it should act as a transformer on runtime to map the types to a single type. This way any code logic dealing with XarrayLike can operate under a single-type assumption.

I think the resultant unified datatype should be xr.Dataset because:

  • xr.DataArray is, I believe, fully representable within a dataset. i.e. a dataset with one array. 1
  • xr.Dataset is already one half of the representable types of XarrayLike
  • I'm ignoring pandas for now as out of scope...

risks:

  • refactoring required and code cleaning
  • need to make sure functionality is not affected: luckily we have good coverage

benefits:

  • less code bloat.
  • any common utility function only needs to deal with one type.
  • less adhoc branching logic - each branch logic has added chance of error.
  • tests can focus more on internal logic rather than repeatedly testing for handling the two types.

Describe alternatives you've considered

  • Standardize to xr.DataArray instead 1
  • Honestly, if a xr.DataArray is fully representable by a xr.Dataset, then this is a hard solution to beat. Any alternative would have to be some other data structure that can interface between the two more smoothly than xr.Dataset inherently can.

Footnotes

  1. The reverse is not true (i.e. xr.Dataset is not fully representable as a xr.DataArray) - and we will have to invent our own collection to standardise a dataset to a data array. 2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions