Skip to content

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

Closed
wants to merge 17 commits into from
Closed

Type NDArrayMixin #6239

wants to merge 17 commits into from

Conversation

Illviljan
Copy link
Contributor

Activate typing on these mixins by removing the Any.

  • Closes #xxxx
  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

@Illviljan
Copy link
Contributor Author

pre-commit.ci autofix

return self.array.dtype

@property
def shape(self: Any) -> tuple[int]:
Copy link
Contributor Author

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?

@Illviljan
Copy link
Contributor Author

Illviljan commented Feb 5, 2022

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?

@mathause
Copy link
Collaborator

mathause commented Feb 7, 2022

I think BackendArray (and it's parents) did not define shape as an attribute. So one option is to revert this change.


The other is to unify how the backends assign shape and dtype? They seem be to defined very differently depending on the backend.

@property
def shape(self):
return self.array.shape

self.shape = array.shape

self._shape = (riods.count, riods.height, riods.width)

@Illviljan
Copy link
Contributor Author

I think BackendArray (and it's parents) did not define shape as an attribute. So one option is to revert this change.

Yeah this approach isn't working that great. I think I'll close this pr unless there's some other ideas.

@mathause
Copy link
Collaborator

mathause commented Feb 7, 2022

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.

@Illviljan Illviljan closed this Aug 12, 2022
@Illviljan Illviljan deleted the ndlen_typing branch August 12, 2022 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants