-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Type NDArrayMixin #6239
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
Type NDArrayMixin #6239
Conversation
pre-commit.ci autofix |
return self.array.dtype | ||
|
||
@property | ||
def shape(self: Any) -> tuple[int]: |
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.
Anyone understands why tuple[int]
(single int) was ok before?
The errors looks like this: self = <xarray.backends.scipy_.ScipyArrayWrapper object at 0x00000234CBC43610>
variable_name = 'dim2'
datastore = <xarray.backends.scipy_.ScipyDataStore object at 0x00000234CBC43D90>
def __init__(self, variable_name, datastore):
self.datastore = datastore
self.variable_name = variable_name
array = self.get_variable().data
> self.shape = array.shape
E AttributeError: can't set attribute
/home/runner/work/xarray/xarray/xarray/backends/scipy_.py:52: AttributeError Setting shape like this doesn't seem like the proper way of doing it. Maybe these should just inherit NDArrayMixin as well? |
I think The other is to unify how the backends assign xarray/xarray/backends/pydap_.py Lines 28 to 30 in d47cf0c
xarray/xarray/backends/netCDF4_.py Line 59 in d47cf0c
xarray/xarray/backends/rasterio_.py Line 37 in d47cf0c
|
Yeah this approach isn't working that great. I think I'll close this pr unless there's some other ideas. |
Define class BackendArray(...):
@property
def shape(self) -> tuple(int, ...):
return self._shape and then set class SpecificBackend(BackendArray):
def __init__(self, variable_name, datastore):
self._shape = array.shape but that might affect downstream libraries. |
Activate typing on these mixins by removing the Any.
whats-new.rst
api.rst