Skip to content

Reimplement Datatree typed ops #9619

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

Merged
merged 23 commits into from
Oct 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
812d207
test unary op
TomNicholas Oct 13, 2024
1b9c089
implement and generate unary ops
TomNicholas Oct 13, 2024
2d9cef4
test for unary op with inherited coordinates
TomNicholas Oct 13, 2024
4bb8902
re-enable arithmetic tests
TomNicholas Oct 13, 2024
8e7c1da
implementation for binary ops
TomNicholas Oct 13, 2024
909ae0e
test ds * dt commutativity
TomNicholas Oct 13, 2024
03ce2c5
ensure other types defer to DataTree, thus fixing #9365
TomNicholas Oct 13, 2024
12112f1
test for inplace binary op
TomNicholas Oct 13, 2024
b823290
pseudocode implementation of inplace binary op, and xfail test
TomNicholas Oct 13, 2024
7147bb3
remove some unneeded type: ignore comments
TomNicholas Oct 14, 2024
368d456
return type should be DataTree
TomNicholas Oct 14, 2024
2c740b4
type datatree ops as accepting dataset-compatible types too
TomNicholas Oct 14, 2024
1eae418
use same type hinting hack as Dataset does for __eq__ not being same …
TomNicholas Oct 14, 2024
bb019da
ignore return type
TomNicholas Oct 14, 2024
20199cb
add some methods to api docs
TomNicholas Oct 14, 2024
7634b6c
don't try to import DataTree.astype in API docs
TomNicholas Oct 14, 2024
2814801
test to check that single-node trees aren't broadcast
TomNicholas Oct 14, 2024
1fcbe02
Merge branch 'main' into datatree-ops
TomNicholas Oct 15, 2024
9e2dfad
return NotImplemented
TomNicholas Oct 15, 2024
399c6e1
Merge branch 'datatree-ops' of https://github.com/TomNicholas/xarray …
TomNicholas Oct 15, 2024
304eb19
remove pseudocode for inplace binary ops
TomNicholas Oct 15, 2024
7dbc817
Merge branch 'main' into datatree-ops
TomNicholas Oct 15, 2024
c7d8060
map_over_subtree -> map_over_datasets
TomNicholas Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test ds * dt commutativity
  • Loading branch information
TomNicholas committed Oct 13, 2024
commit 909ae0e949286bd659769ef8b493898f9fdfca03
24 changes: 23 additions & 1 deletion xarray/tests/test_datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,29 @@ def test_arithmetic_inherited_coords(self):
expected["/foo/bar"].data = np.array([8, 10, 12])
assert_identical(actual, expected)

# TODO test dataset * datatree commutativity
def test_binary_op_commutativity_with_dataset(self):
# regression test for #9365

ds1 = xr.Dataset({"a": [5], "b": [3]})
ds2 = xr.Dataset({"x": [0.1, 0.2], "y": [10, 20]})
dt = DataTree.from_dict(
{
"/": ds1,
"/subnode": ds2,
}
)

other_ds = xr.Dataset({"z": ("z", [0.1, 0.2])})

expected = DataTree.from_dict(
{
"/": ds1 * other_ds,
"/subnode": ds2 * other_ds,
}
)

result = other_ds * dt
assert_equal(result, expected)

# TODO test single-node datatree doesn't broadcast

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy