@@ -668,23 +668,25 @@ def _validate_names(names: Sequence[Hashable] | None) -> None:
668
668
raise ValueError ("Names should be an ordered collection." )
669
669
670
670
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
682
674
683
- # Extract some of the arguments (pass chunksize on).
684
675
iterator = kwds .get ("iterator" , False )
685
676
chunksize = kwds .get ("chunksize" , None )
686
677
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
+
688
690
errors = kwds .get ("encoding_errors" , "strict" )
689
691
if not isinstance (errors , str ):
690
692
raise ValueError (
@@ -716,7 +718,8 @@ def _read(
716
718
return parser
717
719
718
720
with parser :
719
- return parser .read (nrows )
721
+ return parser .read (nrows ) # <== ⚠ THIS LINE must be INSIDE the function!
722
+
720
723
721
724
722
725
@overload
0 commit comments