5555
5656from hamilton import registry
5757from hamilton .io import utils
58- from hamilton .io .data_adapters import DataLoader
58+ from hamilton .io .data_adapters import DataLoader , DataSaver
5959
6060DATAFRAME_TYPE = pl .LazyFrame
6161COLUMN_TYPE = pl .Expr
@@ -297,25 +297,25 @@ def name(cls) -> str:
297297 return "feather"
298298
299299
300-
301300@dataclasses .dataclass
302- class PolarsSinkParquetWriter (DataLoader ):
301+ class PolarsSinkParquetWriter (DataSaver ):
303302 """
304303 Class specifically to handle writing parquet files with Polars LazyFrame.
305304 Should map to https://docs.pola.rs/api/python/stable/reference/lazyframe/api/polars.LazyFrame.sink_parquet.html
306305 """
306+
307307 path : Union [str , Path ]
308308 # kwargs:
309309 compression : str = "zstd"
310310 compression_level : Optional [int ] = None
311311 statistics : bool = False
312312 row_group_size : Optional [int ] = None
313313 data_page_size : Optional [int ] = None
314-
314+
315315 @classmethod
316316 def applicable_types (cls ) -> Collection [Type ]:
317317 return [DATAFRAME_TYPE ]
318-
318+
319319 def _get_writing_kwargs (self ):
320320 kwargs = {}
321321 if self .compression is not None :
@@ -329,23 +329,24 @@ def _get_writing_kwargs(self):
329329 if self .data_page_size is not None :
330330 kwargs ["data_page_size" ] = self .data_page_size
331331 return kwargs
332-
332+
333333 def save_data (self , data : DATAFRAME_TYPE ) -> Dict [str , Any ]:
334334 data .sink_parquet (self .path , ** self ._get_writing_kwargs ())
335335 metadata = utils .get_file_metadata (self .path )
336336 return metadata
337-
337+
338338 @classmethod
339339 def name (cls ) -> str :
340340 return "parquet"
341341
342342
343343@dataclasses .dataclass
344- class PolarsSinkCSVWriter (DataLoader ):
344+ class PolarsSinkCSVWriter (DataSaver ):
345345 """
346346 Class specifically to handle writing CSV files with Polars LazyFrame.
347347 Should map to https://docs.pola.rs/api/python/stable/reference/lazyframe/api/polars.LazyFrame.sink_csv.html
348348 """
349+
349350 path : Union [str , Path ]
350351 # kwargs:
351352 include_bom : bool = False
@@ -360,11 +361,11 @@ class PolarsSinkCSVWriter(DataLoader):
360361 float_precision : Optional [int ] = None
361362 null_value : Optional [str ] = None
362363 quote_style : Optional [str ] = None
363-
364+
364365 @classmethod
365366 def applicable_types (cls ) -> Collection [Type ]:
366367 return [DATAFRAME_TYPE ]
367-
368+
368369 def _get_writing_kwargs (self ):
369370 kwargs = {}
370371 if self .include_bom is not None :
@@ -392,71 +393,72 @@ def _get_writing_kwargs(self):
392393 if self .quote_style is not None :
393394 kwargs ["quote_style" ] = self .quote_style
394395 return kwargs
395-
396+
396397 def save_data (self , data : DATAFRAME_TYPE ) -> Dict [str , Any ]:
397398 data .sink_csv (self .path , ** self ._get_writing_kwargs ())
398399 metadata = utils .get_file_metadata (self .path )
399400 return metadata
400-
401+
401402 @classmethod
402403 def name (cls ) -> str :
403404 return "csv"
404405
405406
406407@dataclasses .dataclass
407- class PolarsSinkIPCWriter (DataLoader ):
408+ class PolarsSinkIPCWriter (DataSaver ):
408409 """
409410 Class specifically to handle writing IPC/Feather files with Polars LazyFrame.
410411 Should map to https://docs.pola.rs/api/python/stable/reference/lazyframe/api/polars.LazyFrame.sink_ipc.html
411412 """
413+
412414 path : Union [str , Path ]
413415 # kwargs:
414416 compression : Optional [str ] = "zstd"
415-
417+
416418 @classmethod
417419 def applicable_types (cls ) -> Collection [Type ]:
418420 return [DATAFRAME_TYPE ]
419-
421+
420422 def _get_writing_kwargs (self ):
421423 kwargs = {}
422424 if self .compression is not None :
423425 kwargs ["compression" ] = self .compression
424426 return kwargs
425-
427+
426428 def save_data (self , data : DATAFRAME_TYPE ) -> Dict [str , Any ]:
427429 data .sink_ipc (self .path , ** self ._get_writing_kwargs ())
428430 metadata = utils .get_file_metadata (self .path )
429431 return metadata
430-
432+
431433 @classmethod
432434 def name (cls ) -> str :
433435 return "ipc"
434436
435437
436438@dataclasses .dataclass
437- class PolarsSinkNDJSONWriter (DataLoader ):
439+ class PolarsSinkNDJSONWriter (DataSaver ):
438440 """
439441 Class specifically to handle writing NDJSON files with Polars LazyFrame.
440442 Should map to https://docs.pola.rs/api/python/stable/reference/lazyframe/api/polars.LazyFrame.sink_ndjson.html
441443 Note: Load support for NDJSON is not yet implemented.
442444 """
445+
443446 path : Union [str , Path ]
444-
447+
445448 @classmethod
446449 def applicable_types (cls ) -> Collection [Type ]:
447450 return [DATAFRAME_TYPE ]
448-
451+
449452 def save_data (self , data : DATAFRAME_TYPE ) -> Dict [str , Any ]:
450453 data .sink_ndjson (self .path )
451454 metadata = utils .get_file_metadata (self .path )
452455 return metadata
453-
456+
454457 @classmethod
455458 def name (cls ) -> str :
456459 return "ndjson"
457460
458461
459-
460462def register_data_loaders ():
461463 """Function to register the data loaders for this extension."""
462464 for loader in [
0 commit comments