Skip to content

Decide whether cubes are iterable #3186

@DPeterK

Description

@DPeterK

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions