@@ -672,8 +672,31 @@ def _read(
672
672
filepath_or_buffer : FilePath | ReadCsvBuffer [bytes ] | ReadCsvBuffer [str ], kwds
673
673
) -> DataFrame | TextFileReader :
674
674
"""Generic reader of line files."""
675
- # if we pass a date_format and parse_dates=False, we should not parse the
676
- # dates GH#44366
675
+ engine = kwds .get ("engine" , "c" )
676
+
677
+ if engine not in ("c" , "python" , "pyarrow" , "polars" ):
678
+ raise ValueError (f"Unknown engine: { engine } " )
679
+
680
+ if engine == "polars" :
681
+ try :
682
+ import polars as pl # type: ignore[import-untyped]
683
+ except ImportError :
684
+ raise ImportError ("Polars is not installed. Please install it with 'pip install polars'." )
685
+
686
+ # Filter kwargs that are not supported by Polars
687
+ allowed_polars_args = {
688
+ "has_header" , "columns" , "new_columns" , "skip_rows" , "n_rows" ,
689
+ "encoding" , "separator" , "quote_char" , "comment_char" , "null_values"
690
+ }
691
+ polars_kwargs = {k : v for k , v in kwds .items () if k in allowed_polars_args }
692
+
693
+ # Polars doesn't accept Path-like objects directly in all versions, convert to string
694
+ path = str (filepath_or_buffer )
695
+
696
+ df = pl .read_csv (path , ** polars_kwargs ).to_pandas ()
697
+ return df
698
+
699
+ # Default pandas behavior
677
700
if kwds .get ("parse_dates" , None ) is None :
678
701
if kwds .get ("date_format" , None ) is None :
679
702
kwds ["parse_dates" ] = False
@@ -1802,7 +1825,7 @@ def _refine_defaults_read(
1802
1825
kwds ["on_bad_lines" ] = ParserBase .BadLineHandleMethod .WARN
1803
1826
elif on_bad_lines == "skip" :
1804
1827
kwds ["on_bad_lines" ] = ParserBase .BadLineHandleMethod .SKIP
1805
- elif callable (on_bad_lines ):
1828
+ elif callable (on_bad_lines ):
1806
1829
if engine not in ["python" , "pyarrow" ]:
1807
1830
raise ValueError (
1808
1831
"on_bad_line can only be a callable function "
0 commit comments