-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
datatree: Bug with arithmetic between datasets and datatrees (e.g. ds * dt) #9365
Labels
Comments
owenlittlejohns
added
bug
needs triage
Issue that has not been reviewed by xarray team member
topic-DataTree
Related to the implementation of a DataTree class
labels
Aug 14, 2024
TomNicholas
removed
the
needs triage
Issue that has not been reviewed by xarray team member
label
Aug 15, 2024
In the meeting last week @shoyer and I discussed just making this behaviour stricter, so that there was no automatic "broadcasting" of a single-node tree across a multi-node tree. However, we could still allow |
TomNicholas
added a commit
to TomNicholas/xarray
that referenced
this issue
Oct 13, 2024
TomNicholas
added a commit
that referenced
this issue
Oct 15, 2024
* test unary op * implement and generate unary ops * test for unary op with inherited coordinates * re-enable arithmetic tests * implementation for binary ops * test ds * dt commutativity * ensure other types defer to DataTree, thus fixing #9365 * test for inplace binary op * pseudocode implementation of inplace binary op, and xfail test * remove some unneeded type: ignore comments * return type should be DataTree * type datatree ops as accepting dataset-compatible types too * use same type hinting hack as Dataset does for __eq__ not being same as Mapping * ignore return type * add some methods to api docs * don't try to import DataTree.astype in API docs * test to check that single-node trees aren't broadcast * return NotImplemented * remove pseudocode for inplace binary ops * map_over_subtree -> map_over_datasets
Closed by #9619 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is your issue?
Originally posted by @TomNicholas in xarray-contrib/datatree#146
Arithmetic involving one
DataTree
and oneDataset
is supposed to be node-wise, i.e. the operation involving the singleDataset
is automatically applied to every node of the tree individually, returning a new tree, like this:However there is a bad bug:
This didn't return a tree, so arithmetic between Datasets and DataTrees currently doesn't respect commutativity :(
Interestingly this does work fine for python scalars
and for
numpy
arrays:I do have tests for this arithmetic behaviour but it looks like I didn't think to check commutativity in any of those tests!
I haven't looked into this deeply yet but my hunch is that it's something to do with
__mul__
/__rmul__
onDataset
competing for priority with__mul__
/__rmul__
onDataTree
. If that is the case then it might only be possible to fix it upstream in xarray by changing the behaviour ofDataset
to defer toDataTree
...The text was updated successfully, but these errors were encountered: