-
-
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
Cannot inherit DataArray anymore in 0.7 release #728
Comments
This was definitely caused by the refactor of DataArray internals in 0.7.0. I don't think you were doing anything wrong, per se, it's just that the internal refactor changed what you can do with a subclasses in an unexpected way :(. On the plus side, the new code should be better about preserving DataArray subclasses -- new DataArrays should be to the same type as parent objects. However, you will need to preserve the signature of |
Thanks @shoyer , |
@rafa-guedes the
or even simply:
|
Thanks @shoyer that works (: |
@shoyer Then it is not OOP any more ... |
@mathieuS87 I'm not quite sure what you mean there. Do you have a suggested alternative? |
Well, I think pure OOP should support class inheritance. In this case, you can subclass Yes, I have an alternative to suggest: initialise subclass instances in two steps, by creating a public method |
That's not the pythonic perspective (although I can see the attraction). The pythonic way is to override |
Also, even in OOP, I'm not sure every class needs to be designed to support inheritance. There are obvious applications where that is not practical. |
@MaximilianR Okay, but this won't solve the current issue. If you override the |
Why? |
That's the point of this issue, why. Read this comment of @shoyer. |
This is a really painful bug since it leads to all sorts of obscure error messages. Is there a reason inheritance with a different |
No strong reason -- we just didn't really consider (or test) inheritance in the current design. Certainly proposals (and PRs) for a subclassing API would be welcome.
http://xarray.pydata.org/en/stable/internals.html#extending-xarray has some related guidance (I agree it could be louder) |
Thanks, I missed that. |
I understand from @shoyer that inheriting from DataArray may not be the best approach to extend DataArray with other specific methods but this was working before the latest release, and it is not working anymore. Just wondering if this would be some issue caused by new internal structure of DataArray, or maybe something I'm doing wrong?
For example, the code below works using xray.0.6.1:
but it does not work anymore when using the new xarray release. The NewArray instance is actually created, but if I try to access this object, or its narray.coords attribute, I get the traceback below. I can however access some other attributes from narray such as narray.values or narray.dims.
The text was updated successfully, but these errors were encountered: