geoplot icon indicating copy to clipboard operation
geoplot copied to clipboard

AttributeError: 'MultiPolygon' object has no attribute 'exterior' / TypeError: 'MultiPolygon' object is not iterable

Open DanielNobbe opened this issue 1 year ago • 2 comments

When using geoplot with a geopandas dataframe containing MultiPolygon objects in its geometry field, geoplot fails to correctly iterate over the MultiPolygon, and then treats it as a single Polygon, resulting in errors. The fault lies in e.g. https://github.com/ResidentMario/geoplot/blob/2da7dc7392d0c7525db7585fd741e95c124fe5c6/geoplot/geoplot.py#L885 The correct way to iterate over a MultiPolygon is by accessing its geoms attribute, rather than directly iterating over the object.

I am using shapely version 2.0.1, I believe this is the package is what's causing the issue. When downgrading to shapely==1.7.1, the problem is alleviated.

Potential fixes:

  • use the geoms attribute
  • pinning the shapely version

I wouldn't mind making a PR to implement a fix

DanielNobbe avatar Jul 04 '23 11:07 DanielNobbe

I've run into this too, and it'd be great to have a fix!

aeturrell avatar Sep 07 '23 11:09 aeturrell

I can try to fix it. It need a proper test/assertion for a MultiPolygon objects, instead of a so called "Duck test" in line 884 (also appears in line 981 and line 1232)

LiuSeeker avatar Sep 12 '23 05:09 LiuSeeker