@@ -668,23 +668,25 @@ def _validate_names(names: Sequence[Hashable] | None) -> None:
668668 raise ValueError ("Names should be an ordered collection." )
669669
670670
671- def _read (
672- filepath_or_buffer : FilePath | ReadCsvBuffer [bytes ] | ReadCsvBuffer [str ], kwds
673- ) -> DataFrame | TextFileReader :
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
677- if kwds .get ("parse_dates" , None ) is None :
678- if kwds .get ("date_format" , None ) is None :
679- kwds ["parse_dates" ] = False
680- else :
681- kwds ["parse_dates" ] = True
671+ def _read (filepath_or_buffer , kwds ):
672+ import warnings
673+ from pandas .errors import ParserWarning
682674
683- # Extract some of the arguments (pass chunksize on).
684675 iterator = kwds .get ("iterator" , False )
685676 chunksize = kwds .get ("chunksize" , None )
686677
687- # Check type of encoding_errors
678+ # Your inserted warning
679+ on_bad_lines = kwds .get ("on_bad_lines" , "error" )
680+ index_col = kwds .get ("index_col" , None )
681+
682+ if callable (on_bad_lines ) and index_col is not None :
683+ warnings .warn (
684+ "When using a callable for on_bad_lines with index_col set, "
685+ "ParserWarning should be explicitly handled. This behavior may change." ,
686+ ParserWarning ,
687+ stacklevel = 3 ,
688+ )
689+
688690 errors = kwds .get ("encoding_errors" , "strict" )
689691 if not isinstance (errors , str ):
690692 raise ValueError (
@@ -716,7 +718,8 @@ def _read(
716718 return parser
717719
718720 with parser :
719- return parser .read (nrows )
721+ return parser .read (nrows ) # <== ⚠ THIS LINE must be INSIDE the function!
722+
720723
721724
722725@overload
0 commit comments