Skip to content

Commit

Permalink
fix: include index columns for geodataframes
Browse files Browse the repository at this point in the history
  • Loading branch information
hbruch committed Dec 18, 2023
1 parent 4a39ded commit 7a50716
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pipeline/resources/postgis_geopandas_io_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def handle_output(self, context: OutputContext, obj: geopandas.GeoDataFrame):
schema, table = self._get_schema_table(context.asset_key)

if isinstance(obj, geopandas.GeoDataFrame):
len(obj)
with connect_postgresql(config=self._config) as con:
self._create_schema_if_not_exists(schema, con)
if context.has_partition_key:
# add additional column (name? for now just partition)
# to the frame and initialize with partition_name
Expand All @@ -189,9 +189,9 @@ def handle_output(self, context: OutputContext, obj: geopandas.GeoDataFrame):
# All data can be replaced (e.g. deleted before insertion).
# geopandas will take care of this.
if_exists_action = 'replace'

self._create_schema_if_not_exists(schema, con)
obj.to_postgis(con=con, name=table, schema=schema, if_exists=if_exists_action, chunksize=self.chunksize)
obj.to_postgis(
con=con, name=table, index=True, schema=schema, if_exists=if_exists_action, chunksize=self.chunksize
)
context.add_output_metadata({'num_rows': len(obj), 'table_name': f'{schema}.{table}'})
else:
super().handle_output(context, obj)
Expand Down

0 comments on commit 7a50716

Please sign in to comment.