ajdawson / eofs

EOF analysis in Python
http://ajdawson.github.io/eofs/
GNU General Public License v3.0
199 stars 60 forks source link

reconstructedField raises an AttributeError in latest Python / Xarray version #129

Closed mshiv closed 2 years ago

mshiv commented 2 years ago

When I run the following example use case

from eofs.xarray import Eof
solver = Eof(data) # flux is the above DataArray
reconstr = solver.reconstructedField(solver.neofs)

The reconstructedField method call raises an AttributeError, pointing to the following section of the code in /lib/python3.10/site-packages/eofs/standard.py within reconstructedField:

# Determine how the PCs and EOFs will be selected.
if isinstance(neofs, collections.Iterable):
            modes = [m - 1 for m in neofs]
        else:
            modes = slice(0, neofs)

Error raised: AttributeError: module 'collections' has no attribute 'Iterable'

It looks like usage of collections.Iterable has been deprecated, being refactored into a second-level module for "abstract base classes" (a similar issue raised here).

Changing the above to

# Determine how the PCs and EOFs will be selected.
if isinstance(neofs, collections.abc.Iterable):
            modes = [m - 1 for m in neofs]
        else:
            modes = slice(0, neofs)

solved the issue for now.

ajdawson commented 2 years ago

Closed by #130.