Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose dataset reduce operations #10

Merged
merged 9 commits into from
Aug 25, 2021
Merged

Expose dataset reduce operations #10

merged 9 commits into from
Aug 25, 2021

Conversation

TomNicholas
Copy link
Member

@TomNicholas TomNicholas commented Aug 23, 2021

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?)

@TomNicholas TomNicholas changed the title [WIP] Expose dataset ops [WIP] Expose dataset arithmetic operations Aug 24, 2021
@TomNicholas
Copy link
Member Author

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.

@TomNicholas TomNicholas changed the title [WIP] Expose dataset arithmetic operations Expose dataset reduce operations Aug 25, 2021
@TomNicholas TomNicholas merged commit b0b45a2 into main Aug 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 free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant