-
-
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
Use Self
rather than concrete types, remove cast
s
#8216
Conversation
This should also allow for subtyping
for more information, see https://pre-commit.ci
0e38502
to
29084a7
Compare
b667732
to
155ab5d
Compare
1aa3286
to
106c8ce
Compare
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.
That's something I've wanted to do for quite a while now. Thanks!
xarray/core/dataset.py
Outdated
return _broadcast_helper( | ||
cast("T_Dataset", args[1]), exclude, dims_map, common_coords | ||
cast("Dataset", args[1]), exclude, dims_map, common_coords |
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 guess we have to look at what align does to subclasses
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.
Yes, I looked at this, but eventually thought it wasn't worth gating on — it's quite complicated. It's something like "the 'biggest' class" — so "da + da = da", but "da + ds = ds"...
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 adjusted these a bit, see what you think. Allowed removing some cast
s
Co-authored-by: Michael Niklas <[email protected]>
Co-authored-by: Michael Niklas <[email protected]>
Co-authored-by: Michael Niklas <[email protected]>
for more information, see https://pre-commit.ci
xarray/core/coordinates.py
Outdated
@@ -664,6 +664,8 @@ def copy( | |||
variables = { | |||
k: v._copy(deep=deep, memo=memo) for k, v in self.variables.items() | |||
} | |||
# Currently this requires using the concrete type of `Coordinates`, rather than | |||
# `Self`, ref #8216 |
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.
why doesn't type(self) work here?
return type(self)._construct_direct(
coords=variables, indexes=dict(self.xindexes), dims=dict(self.sizes)
)
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 went to answer this question, and then got it working :)
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.
OK actually the typing worked but the tests didn't; switching back. Added a TODO but won't chase it down atm...
This should also allow for subtyping