Skip to content

Commit cde05cc

Browse files
authored
BaseConverter get_columns hook (#13)
* Delay copying self.columns so it can be altered after opening/downloading the file * Add get_columns hook * Add Changelog
1 parent b4d01c1 commit cde05cc

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
- Change default temporal property to datetime
1111
- Enable Converter.columns list and tuple types
12+
- Add BaseConverter get_columns hook to customize columns after reading the file
1213
- Update STAC processing extension
1314

1415
## [v0.2.11] - 2025-10-09

vecorel_cli/conversion/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class BaseConverter(LoggerMixin):
5151
variants: dict[str, Sources] = {}
5252
variant: Optional[str] = None
5353

54-
columns: dict[str, str|Sequence[str]] = {}
54+
columns: dict[str, str | Sequence[str]] = {}
5555
column_additions: dict[str, str] = {}
5656
column_filters: dict[str, Callable] = {}
5757
column_migrations: dict[str, Callable] = {}
@@ -83,6 +83,9 @@ def layer_filter(self, layer: str, uri: str) -> bool:
8383
def post_migrate(self, gdf: GeoDataFrame) -> GeoDataFrame:
8484
return gdf
8585

86+
def get_columns(self, gdf: GeoDataFrame) -> dict[str, str | Sequence[str]]:
87+
return self.columns.copy()
88+
8689
def get_cache(self, cache_folder=None, **kwargs) -> tuple[AbstractFileSystem, str]:
8790
if cache_folder is None:
8891
_kwargs = {}
@@ -299,7 +302,6 @@ def convert(
299302
original_geometries=False,
300303
**kwargs,
301304
) -> str:
302-
columns = self.columns.copy()
303305
self.variant = variant
304306
cid = self.id.strip()
305307
if self.bbox is not None and len(self.bbox) != 4:
@@ -340,6 +342,8 @@ def convert(
340342
gdf = self.migrate(gdf)
341343
assert isinstance(gdf, GeoDataFrame), "Migration function must return a GeoDataFrame"
342344

345+
columns = self.get_columns(gdf)
346+
343347
# 2. Run filters to remove rows that shall not be in the final data
344348
gdf = self.filter_rows(gdf)
345349

0 commit comments

Comments
 (0)