dendrograms / astrodendro

Generate a dendrogram from a dataset
https://dendrograms.readthedocs.io/
Other
37 stars 36 forks source link

Importing "Iterable" needs updating for Python > 3.9 #183

Closed nbrunett closed 2 years ago

nbrunett commented 2 years ago

I was trying to run pycprops in Python 3.10.2 (which uses astrodendro) and encountered the following import error (partial traceback to exclude my scripts and directory names):

File ".../astrodendro/__init__.py", line 3
    from .dendrogram import Dendrogram, periodic_neighbours
File ".../astrodendro/dendrogram.py", line 8
    from collections import Iterable
ImportError: cannot import name 'Iterable' from 'collections'

It looks like importing Iterable from collections has changed after Python 3.9 (see text below the first table at the top of the page here).

Changing line 8 in dendrogram.py from

from collections import Iterable

to

try:
    # Python <= 3.9
    from collections import Iterable
except ImportError:
    # Python > 3.9
    from collections.abc import Iterable

eliminated the problem for me (inspired by suggestion in the comment here).

Let me know if you need any more information.

keflavich commented 2 years ago

could you please submit this as a pull request? It looks like you've found the solution so you should get credit for the change