'Can I save a GeoDataFrame that contains an array to a GeoPackage file?

I have a geopandas GeoDataFrame with some attribute columns and a geometry column (just a regular GDF). Usually I save GDF's as GeoPackage giles (.gpkg) using:

gdf.to_file('path_to_file.gpkg', driver='GPKG')

This works fine, unless my GDF has a column where the entries are arrays. So say I have two columns next to the geometry column and one of them contains a numpy array for each entry. If I then try to save as a gpkg it gives me the error:

ValueError: Invalid field type <class 'numpy.ndarray'>

So it appears that a gpkg cannot handle arrays in the table. The arrays I want to include are simple flags (so values of 0 and 1). I found two workarounds which work alright but are a bit messy:

  1. Make a string of the array values. This works but I would very much prefer leaving it as an array...
  2. Create a separate column for every array value. This would also work but then I get a GDF with a lot of columns and I feel there should be a better way to do this.

Does anybody know of a better workaround to this issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source