-
-
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
DAS-2067 - Migrate datatree io.py and common.py #9011
Changes from 6 commits
9d554da
b3a4662
fecb5d7
6ed1491
9565b41
f3261e7
e968631
3d4ad40
d0eb3ef
34170fa
3dc9dba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,6 +347,34 @@ def _ipython_key_completions_(self) -> list[str]: | |
return list(items) | ||
|
||
|
||
class TreeAttrAccessMixin(AttrAccessMixin): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this class necessary? Can't I think the reason this class existed separately was just to do with hacking around limitations of datatree being in a separate repository... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I initially tried to use I think we talked about this a little bit in one of our calls - things like |
||
"""Mixin class that allows getting keys with attribute access""" | ||
|
||
# TODO: Ensure ipython tab completion can include both child datatrees and | ||
# variables from Dataset objects on relevant nodes. | ||
|
||
__slots__ = () | ||
|
||
def __init_subclass__(cls, **kwargs): | ||
"""Verify that all subclasses explicitly define ``__slots__``. If they don't, | ||
raise error in the core xarray module and a FutureWarning in third-party | ||
extensions. | ||
""" | ||
if not hasattr(object.__new__(cls), "__dict__"): | ||
pass | ||
# TODO Rework DataTree to avoid __dict__. | ||
# elif cls.__module__.startswith("xarray."): | ||
# raise AttributeError(f"{cls.__name__} must explicitly define __slots__") | ||
# else: | ||
# cls.__setattr__ = cls._setattr_dict | ||
# warnings.warn( | ||
# f"xarray subclass {cls.__name__} should explicitly define __slots__", | ||
# FutureWarning, | ||
# stacklevel=2, | ||
# ) | ||
# super().__init_subclass__(**kwargs) | ||
owenlittlejohns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def get_squeeze_dims( | ||
xarray_obj, | ||
dim: Hashable | Iterable[Hashable] | None = None, | ||
|
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.
So here's the biggest question I have... is this okay for now? (Maybe this is directed at @TomNicholas)
The use of
__slots__
is a little new to me (but makes sense from reading up on it). I think to adopt__slots__
and remove__dict__
I would need to slightly reworkDataTree
,TreeNode
andNamedNode
. I wanted to check that the scope mainly seems to beself.children
andself.parent
attributes, and understand why those classes were implemented as they currently are before trying to alter things.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.
This is going to embarrass me, but why did you stop calling init_subclass on the Parent object? everything else with this merge seems reasonable to me.
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.
Good catch. I accidentally commented out that last line. Will fix!
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.
So, my last comment was true, but... uncommenting out that line means that the same method in the parent class (
AttrAccessMixin
) gets called bysuper
in addition to this method, right? That would mean we end up calling the validation logic that this child method is trying to avoid for now (checking that__dict__
is not present on the class).Now if only I'd said that the first time around 😉