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

Decide whether cubes are iterable #3186

Closed
DPeterK opened this issue Oct 4, 2018 · 1 comment · Fixed by #3656
Closed

Decide whether cubes are iterable #3186

DPeterK opened this issue Oct 4, 2018 · 1 comment · Fixed by #3656

Comments

@DPeterK
Copy link
Member

DPeterK commented Oct 4, 2018

At the moment, cubes report as being iterables, but raise an error if you try to iterate over a cube:

>>> isinstance(cube, Iterable)
True

>>> for c in cube:
...     print c

TypeError: Cube is not iterable

This is confusing and potentially a bit awkward, as it looks like Iris can't make its mind up...

Of course this comes down to the presence of the __iter__ method, whose presence means the Cube class reports as being iterable, while the method itself just raises an error. We could:

  • remove the __iter__ method, which is simple to do but unfortunately reverses the problem (Cube reports as not being iterable, while you actually can then iterate over a cube on its leading dimension)
  • explicitly support iterating by extending __iter__, which is more complicated and potentially undefined
  • ... do something more clever than either of these suggestions
  • just ignore it
@pp-mo
Copy link
Member

pp-mo commented Nov 5, 2018

Long long ago...
we explicitly stopped cubes being iterables because it was confusing a lot of users.
See : #86

Of course, we might decide that this now no longer applies.
Anyway, please review pros+cons from the older discussion

@rcomer rcomer linked a pull request Feb 13, 2020 that will close this issue
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 a pull request may close this issue.

2 participants