-
-
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
Enable datatree * dataset commutativity #7497
Conversation
… into import_datatree
… into import_datatree
Co-authored-by: Joe Hamman <[email protected]>
for more information, see https://pre-commit.ci
… into import_datatree
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
… into import_datatree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great, thank you!
|
||
.. _netcdf.group.warning: | ||
|
||
.. warning:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have this same issue with round-tripping Dataset objects. Unless it's particularly more pronounced for Datatree objects, I would consider consolidating the discussion, maybe in a new section like "netCDF files that Xarray cannot represent."
.. note:: | ||
Note that perfect round-tripping should always be possible with a zarr store (:ref:`unlike for netCDF files<netcdf.group.warning>`), | ||
as zarr does not support "unused" dimensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just leave this note under the netCDF section -- only people concerned about netCDF need to worry about this
except ImportError: | ||
raise ImportError( | ||
"Could not import the datatree package. " | ||
"Find it at https://github.com/xarray-contrib/datatree" | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python will give more informative error message ("The above exception was the direct cause of the following exception") if you use raise ... from ...
here:
except ImportError: | |
raise ImportError( | |
"Could not import the datatree package. " | |
"Find it at https://github.com/xarray-contrib/datatree" | |
) | |
except ImportError as e: | |
raise ImportError( | |
"Could not import the datatree package. " | |
"Find it at https://github.com/xarray-contrib/datatree" | |
) from e |
try: | ||
from datatree import DataTree | ||
|
||
if isinstance(other, DataTree): | ||
return NotImplemented | ||
except ImportError: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using contextlib.suppress()
here: https://docs.python.org/3/library/contextlib.html#contextlib.suppress
# This ordering won't work unless xarray.Dataset defers to DataTree. | ||
# See https://github.com/xarray-contrib/datatree/issues/146 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably this comment can be deleted now :)
ds1 = Dataset({"a": [5], "b": [3]}) | ||
ds2 = Dataset({"x": [0.1, 0.2], "y": [10, 20]}) | ||
dt = DataTree(data=ds1) | ||
DataTree(name="subnode", data=ds2, parent=dt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this line do anything?
other_ds = Dataset({"z": ("z", [0.1, 0.2])}) | ||
|
||
expected = DataTree(data=ds1 * other_ds) | ||
DataTree(name="subnode", data=ds2 * other_ds, parent=expected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same concern as above
This was superceded by #9619 |
Change binary operations involving
DataTree
objects andDataset
objects to be handled by theDataTree
class. Necessary to enableds * dt
to return the same type asdt * ds
.Builds on top of #7418.
whats-new.rst
api.rst