Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.

Expose dataset reduce operations - #10

Merged
TomNicholas merged 9 commits into
mainfrom
expose_dataset_ops
Aug 25, 2021
Merged

Expose dataset reduce operations#10
TomNicholas merged 9 commits into
mainfrom
expose_dataset_ops

Conversation

@TomNicholas

@TomNicholasTomNicholas commented Aug 23, 2021

Copy link
Copy Markdown
Member

A WIP attempt to get operations like * and + working on DatasetNode objects.

Idea is to copy the pattern used to add these operators to xarray.Dataset, where Dataset inherits from DatasetArithmetic.

DatasetArithmetic itself inherits from about 5 different Mixin classes, which I don't particularly want to regenerate, especially as DatasetOpsMixin is generated by templating in xarray. Here we instead just want to take the methods defined on DatasetArithmetic and decorate them with map_over_subtree, to get a DataTreeArithmetic object to inherit from.

Problem is at the moment I'm getting errors like this:

> result = dt * dt
E TypeError: unsupported operand type(s) for *: 'DatasetNode' and 'DatasetNode'

I don't understand why this is happening because __mul__ and __rmul__ are definitely defined on the dt objects. (Could it be because those methods get defined only once the object instance has been created, and not when the class is defined?)

@TomNicholasTomNicholas changed the title [WIP] Expose dataset ops[WIP] Expose dataset arithmetic operationsAug 24, 2021
@TomNicholas

Copy link
Copy Markdown
MemberAuthor

In a twist of events this PR has ended up accidentally successfully implementing reduce and cumulative methods such as .mean() and .cumsum(). This happened because I generalized the PR to make DataTree inherit from xarray.core.Dataset.DataWithCoords and xarray.core.Dataset.DatasetArithmetic instead of just xarray.core._typed_ops.DatasetOpsMixin (which is a superclass of xarray.core.Dataset.DatasetArithmetic).

However I still haven't got numpy ufuncs or binary arithmetic operations like multiply working, but I'll discuss them in separate issue.

@TomNicholasTomNicholas changed the title [WIP] Expose dataset arithmetic operationsExpose dataset reduce operationsAug 25, 2021
@TomNicholas
TomNicholas merged commit b0b45a2 into mainAug 25, 2021
@TomNicholas
TomNicholas deleted the expose_dataset_ops branch August 25, 2021 04:26
flamingbear pushed a commit to flamingbear/rewritten-datatree that referenced this pull request Jan 19, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@TomNicholas