pbugnion / gmaps

Google maps for Jupyter notebooks
https://jupyter-gmaps.readthedocs.io/en/stable/
Other
760 stars 147 forks source link

API change for collections in Python 3.3+ breaks is_atomic in options.py #352

Open whudson opened 2 years ago

whudson commented 2 years ago

Running in Python 3.10 and calling gmaps.symbol_layer() with info_boxes set to a list of strings:

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\gmaps\options.py:40, in is_atomic(elem)
     34 def is_atomic(elem):
     35     """
     36     True if an element is a single atom and false if it's a collection
     37     """
     38     return (
     39         isinstance(elem, string_types) or
---> 40         not isinstance(elem, collections.Iterable)
     41     )

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

In python 3.3+ these are moved into the collections.abc (abstract base classes) module. For some reason I have to access them like this when testing in my code:

import _collections_abc
_collections_abc.Iterable
whudson commented 2 years ago

Sorry I'm getting myself confused here. Creating a layer with one argument works, but adding additional options fails at the is_atomic function. I'll try to send a PR for this later.

whudson commented 2 years ago

Apparently the correct way to do it is one of:

from collections.abc import *
from collections import abc

I'm not sure how the CI tests are passing on the existing build for v3.3+, but changing the import was definitely needed on my machine.

timcoote commented 1 year ago

This bug wasn't evident with Pyhton 3.9, but it is with 3.10.

whudson commented 1 year ago

I'm not sure how to fix this in a good way - I'll leave it up to someone else.

madappally commented 1 year ago

As a temporary workaround, add these lines in your script.

import collections
collections.Iterable = collections.abc.Iterable