Skip to content
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

BUG: unyt_quantity are Sized objects without a length ? #201

Closed
neutrinoceros opened this issue Sep 6, 2021 · 2 comments
Closed

BUG: unyt_quantity are Sized objects without a length ? #201

neutrinoceros opened this issue Sep 6, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@neutrinoceros
Copy link
Member

  • unyt version: 2.8.0
  • Python version: 3.9.6
  • Operating System: OS/X

Description

unyt_quantity objects are recognised as instances of collections.abc.Sized, which indicates that they have a __len__� protocol. However, calling len(quantity) fails with an error message contradicting this.

What I Did

from collections.abc import Sized
import unyt as un

quan = un.unyt_quantity(1, "cm")
assert isinstance(quan, Sized)
print(len(quan))

output

TypeError: len() of unsized object
@neutrinoceros
Copy link
Member Author

So there would be two concurrent approaches to solving this. The first possibility would be to make all quantities have len 1.
Since quand[0] returns an error too however, I suppose that the issue is really that isinstance(quan, Sized) evaluates as True, which is likely a direct consequence of inheriting from unyt_array

@neutrinoceros
Copy link
Member Author

Turns out this isn't specific to unyt but is generally true with numpy 0d ndarrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant