@@ -76,6 +76,7 @@ def __init__(self):
7676 self .crs : Union [str , Tuple [str , str ]] = DEFAULT_CRS
7777 self ._instance : Optional [LoaderBase ] = None
7878 self ._preview : Optional [dict ] = None
79+ self ._columns_configured : bool = False
7980
8081 def _reset (self ):
8182 self .source_type = None
@@ -91,6 +92,7 @@ def _reset(self):
9192 self .debug_limit_list_datasets = None
9293 self ._instance = None
9394 self ._preview = None
95+ self ._columns_configured = False
9496
9597 def from_file (self , file_path : str ) -> "LoaderFactory" :
9698 """Configure the factory to load data from a file.
@@ -195,7 +197,7 @@ def with_columns(
195197 geometry_column : Optional [str ] = None ,
196198 ) -> "LoaderFactory" :
197199 """Specify either the latitude and longitude columns or a single geometry column in the data source.
198-
200+
199201 This method configures which columns in the data source contain the latitude,
200202 longitude coordinates, or geometry data. Either both `latitude_column` and
201203 `longitude_column` must be set, or `geometry_column` must be set.
@@ -214,9 +216,21 @@ def with_columns(
214216 >>> loader = mapper.loader.from_file("data/points.csv")\
215217 ... .with_columns(geometry_column="geom")
216218 """
219+ if self ._columns_configured :
220+ raise ValueError (
221+ "with_columns has already been configured for this loader. "
222+ "Each loader instance can only define one coordinate configuration "
223+ "(for example choose either pickup or dropoff coordinates when working "
224+ "with taxi trips). Create a new loader to configure another set of coordinates."
225+ )
217226 self .latitude_column = latitude_column
218227 self .longitude_column = longitude_column
219228 self .geometry_column = geometry_column
229+ if any (
230+ value is not None
231+ for value in (latitude_column , longitude_column , geometry_column )
232+ ):
233+ self ._columns_configured = True
220234 logger .log (
221235 "DEBUG_LOW" ,
222236 f"WITH_COLUMNS: Initialised LoaderFactory "
0 commit comments