def polygons_to_geom_dicts(polygons, skip_invalid=True):
interface = polygons.interface.datatype<EOL>if interface == '<STR_LIT>':<EOL><INDENT>return [row.to_dict() for _, row in polygons.data.iterrows()]<EOL><DEDENT>elif interface == '<STR_LIT>':<EOL><INDENT>return polygons.data<EOL><DEDENT>polys = []<EOL>xdim, ydim = polygons.kdims<EOL>has_holes = polygons.has_holes<EOL>holes = polygons.holes() if has_holes else None<EOL>for i, polygon in enumerate(polygons.split(datatype='<STR_LIT>')):<EOL><INDENT>array = np.column_stack([polygon.pop(xdim.name), polygon.pop(ydim.name)])<EOL>splits = np.where(np.isnan(array[:, :<NUM_LIT:2>].astype('<STR_LIT:float>')).sum(axis=<NUM_LIT:1>))[<NUM_LIT:0>]<EOL>arrays = np.split(array, splits+<NUM_LIT:1>) if len(splits) else [array]<EOL>invalid = False<EOL>subpolys = []<EOL>subholes = None<EOL>if has_holes:<EOL><INDENT>subholes = [[LinearRing(h) for h in hs] for hs in holes[i]]<EOL><DEDENT>for j, arr in enumerate(arrays):<EOL><INDENT>if j != (len(arrays)-<NUM_LIT:1>):<EOL><INDENT>arr = arr[:-<NUM_LIT:1>] <EOL><DEDENT>if len(arr) == <NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>elif len(arr) == <NUM_LIT:1>:<EOL><INDENT>if skip_invalid:<EOL><INDENT>continue<EOL><DEDENT>poly = Point(arr[<NUM_LIT:0>])<EOL>invalid = True<EOL><DEDENT>elif len(arr) == <NUM_LIT:2>:<EOL><INDENT>if skip_invalid:<EOL><INDENT>continue<EOL><DEDENT>poly = LineString(arr)<EOL>invalid = True<EOL><DEDENT>elif not len(splits):<EOL><INDENT>poly = Polygon(arr, (subholes[j] if has_holes else []))<EOL><DEDENT>else:<EOL><INDENT>poly = Polygon(arr)<EOL>hs = [h for h in subholes[j]] if has_holes else []<EOL>poly = Polygon(poly.exterior, holes=hs)<EOL><DEDENT>subpolys.append(poly)<EOL><DEDENT>if invalid:<EOL><INDENT>polys += [dict(polygon, geometry=sp) for sp in subpolys]<EOL>continue<EOL><DEDENT>elif len(subpolys) == <NUM_LIT:1>:<EOL><INDENT>geom = subpolys[<NUM_LIT:0>]<EOL><DEDENT>elif subpolys:<EOL><INDENT>geom = MultiPolygon(subpolys)<EOL><DEDENT>else:<EOL><INDENT>continue<EOL><DEDENT>polygon['<STR_LIT>'] = geom<EOL>polys.append(polygon)<EOL><DEDENT>return polys<EOL>
Converts a Polygons element into a list of geometry dictionaries,
preserving all value dimensions.

For array conversion the following conventions are applied:

* Any nan separated array are converted into a MultiPolygon
* Any array without nans is converted to a Polygon
* If there are holes associated with a nan separated array
  the holes are assigned to the polygons by testing for an
  intersection
* If any single array does not have at least three coordinates
  it is skipped by default
* If skip_invalid=False and an array has less than three
  coordinates it will be converted to a LineString