Skip to content

Commit 09d10d2

Browse files
Anurag-42elsayedhazemm
authored andcommitted
FIX: read_csv: Implement string-based 'on_bad_lines' options for C engine
1 parent c30677d commit 09d10d2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pandas/_libs/parsers.pyx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,21 @@ cdef class TextReader:
461461
raise ValueError("Only length-1 comment characters supported")
462462
self.parser.commentchar = <char>ord(comment)
463463

464-
self.parser.on_bad_lines = on_bad_lines
464+
if isinstance(on_bad_lines, str):
465+
if on_bad_lines == 'error':
466+
c_on_bad_lines = ERROR
467+
elif on_bad_lines == 'warn':
468+
c_on_bad_lines = WARN
469+
elif on_bad_lines == 'skip':
470+
c_on_bad_lines = SKIP
471+
# Note: can add 'skip_with_log' here later when we work on logging
472+
else:
473+
raise ValueError(f"Invalid value for on_bad_lines: {on_bad_lines}")
474+
else:
475+
# If it's not a string, assume it's already an integer/enum constant (like ERROR)
476+
c_on_bad_lines = on_bad_lines
477+
478+
self.parser.on_bad_lines = c_on_bad_lines
465479

466480
self.skiprows = skiprows
467481
if skiprows is not None:

0 commit comments

Comments
 (0)