#### Shapely deprecation warning with combination multipolygon and polygon how to solve

I am trying to plot some data on a map, where counties are colored in based on certain values. This worked fine before (first picture), but now leaves the plots empty (second picture) with many Shapely deprecation warnings.

Reading up on the issue with the deprecation warning both here and here, I have tried using .geoms, but the data seems to be a combination of MultiPolygons and Polygons. This prevents me from using .geoms effectively.

How can I edit my code such that I get the plots that I need with Shapely 1.8.0 and up?

My code originally:

``````poly = [df.loc[df['NAME_0'] == 'Sweden']['geometry'].values[0]]
msk = Polygon(rect_from_bound(*exts)).difference( poly[0].simplify(0.01) )
msk_stm  = st_proj.project_geometry (msk, projection)  # project geometry to the projection used by stamen

cs1 = axs[0].contourf(lons, lats, FWI_sum, 60, transform=projection, levels=levels, cmap=cmap, extend='both')
cs11 = axs[0].contourf(lons2, lats2, forest_output, 60, transform=projection, levels=levels2, cmap=cmap2, extend='both')
axs[0].coastlines()
axs[0].set_extent(extent, projection)
axs[0].axis('off')
for county in counties:
poly2 = df2.loc[df2['name'] == county]['geometry'].values

cs12 = axs[1].contourf(lons2, lats2, forest_output, 60, transform=projection, levels=levels2, cmap=cmap2, extend='both')
axs[1].set_extent(extent, projection)
axs[1].coastlines(resolution='10m')
axs[1].axis('off')

for county, fireextentcounty_norm in zip(counties, fireextentcounties_norm):
poly3 = df2.loc[df2['name'] == county]['geometry'].values
rgba2 = cmap3(fireextentcounty_norm)

cs13 = axs[2].contourf(lons2, lats2, forest_output, 60, transform=projection, levels=levels2, cmap=cmap2, extend='both')
axs[2].set_extent(extent, projection)
axs[2].coastlines(resolution='10m')
axs[2].axis('off')

for county, firenumbercounty_norm in zip(counties, firenumbercounties_norm):
poly4 = df2.loc[df2['name'] == county]['geometry'].values
rgba3 = cmap4(firenumbercounty_norm)
``````

Which gave these warnings:

``````Warning (from warnings module):
File "/usr/lib/python3/dist-packages/cartopy/feature/__init__.py", line 217
self._geoms = tuple(geometries)
ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.

Warning (from warnings module):
File "/usr/lib/python3/dist-packages/cartopy/feature/__init__.py", line 217
self._geoms = tuple(geometries)
ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.

Warning (from warnings module):
File "/usr/lib/python3/dist-packages/cartopy/feature/__init__.py", line 217
self._geoms = tuple(geometries)
ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.

Warning (from warnings module):
File "/usr/lib/python3/dist-packages/cartopy/feature/__init__.py", line 217
self._geoms = tuple(geometries)
ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.

Warning (from warnings module):
File "/usr/lib/python3/dist-packages/cartopy/feature/__init__.py", line 217
self._geoms = tuple(geometries)
ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.

Warning (from warnings module):
File "/usr/lib/python3/dist-packages/cartopy/feature/__init__.py", line 217
self._geoms = tuple(geometries)
ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
``````

My code now:

``````poly = [df.loc[df['NAME_0'] == 'Sweden']

['geometry'].values[0]]
msk = Polygon(rect_from_bound(*exts)).difference( poly[0].simplify(0.01) )
msk_stm  = st_proj.project_geometry (msk, projection)  # project geometry to the projection used by stamen

cs1 = axs[0].contourf(lons, lats, FWI_sum, 60, transform=projection, levels=levels, cmap=cmap, extend='both')
cs11 = axs[0].contourf(lons2, lats2, forest_output, 60, transform=projection, levels=levels2, cmap=cmap2, extend='both')
axs[0].coastlines()
axs[0].set_extent(extent, projection)
axs[0].axis('off')
for county in counties:
poly2 = df2.loc[df2['name'] == county]['geometry'].values
print(poly2[0].geoms)

cs12 = axs[1].contourf(lons2, lats2, forest_output, 60, transform=projection, levels=levels2, cmap=cmap2, extend='both')
axs[1].set_extent(extent, projection)
axs[1].coastlines(resolution='10m')
axs[1].axis('off')

for county, fireextentcounty_norm in zip(counties, fireextentcounties_norm):
poly3 = df2.loc[df2['name'] == county]['geometry'].values
rgba2 = cmap3(fireextentcounty_norm)

cs13 = axs[2].contourf(lons2, lats2, forest_output, 60, transform=projection, levels=levels2, cmap=cmap2, extend='both')
axs[2].set_extent(extent, projection)
axs[2].coastlines(resolution='10m')
axs[2].axis('off')

for county, firenumbercounty_norm in zip(counties, firenumbercounties_norm):
poly4 = df2.loc[df2['name'] == county]['geometry'].values
rgba3 = cmap4(firenumbercounty_norm)
``````

Which gives these errors:

``````Warning (from warnings module):
File "/usr/lib/python3/dist-packages/cartopy/feature/__init__.py", line 217
self._geoms = tuple(geometries)
ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry.

Warning (from warnings module):
File "/usr/lib/python3/dist-packages/cartopy/feature/__init__.py", line 217
self._geoms = tuple(geometries)
ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the  number of parts of a multi-part geometry.
<shapely.geometry.base.GeometrySequence object at 0x74aa047dbf40>
<shapely.geometry.base.GeometrySequence object at 0x74aa047dbf10>
<shapely.geometry.base.GeometrySequence object at 0x74aa047fcee0>
<shapely.geometry.base.GeometrySequence object at 0x74aa047fdd50>
<shapely.geometry.base.GeometrySequence object at 0x74aa047fe890>
Traceback (most recent call last):
File "/usr/lib/python3.10/idlelib/run.py", line 578, in runcode
exec(code, self.locals)
File "/home/els/Nextcloud/Documents/PhD/damage_index/FWImodel/Plotting/PlotYearSum.py", line 182, in <module>
print(poly2[0].geoms)
AttributeError: 'Polygon' object has no attribute 'geoms'. Did you mean: '_geom'?
``````