Skip to content

Commit

Permalink
Modify table_to_gpkg
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-tomasini committed Dec 19, 2024
1 parent 3f804ee commit 12a3719
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/general_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,16 @@ def convert_list_to_string(list_data: list) -> str:

def table_to_gpkg(table: pl.DataFrame, gpkg_file_name: str, layer_name: str):
"""
Save a Polars DataFrame as a GeoPackage file.
Save a Polars DataFrame as a GeoPackage file. As GeoPackage does not support list columns,
the list columns are joined into a single string separated with a comma.
Args:
table (pl.DataFrame): The Polars DataFrame.
gpkg_file_name (str): The GeoPackage file name.
layer_name (str): The layer name.
"""
list_columns: list[str] = [name for name, col_type in dict(table.schema).items() if type(col_type) == pl.List]
list_columns: list[str] = [
name for name, col_type in dict(table.schema).items() if type(col_type) == pl.List]
table_pd: pd.DataFrame = table.with_columns(
c(list_columns).list.join(", ")
).to_pandas()
Expand Down

0 comments on commit 12a3719

Please sign in to comment.