-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DEPR: error_bad_lines and warn_bad_lines for read_csv #40413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
4e867e9
d230035
ce5bf29
8629f87
06f87a1
edeef7e
f806a4d
5b08a88
af3fd15
f70f34e
0c76180
a0406b5
89fdc70
f7265a3
1e20b53
2e79f9a
fe7541c
772c13f
d00e601
e267aa4
e724d0b
fdef68e
a220293
9b8468a
a6af9aa
2f70edc
93c37df
cf3201c
4911b27
f28316b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from collections import defaultdict | ||
import csv | ||
import datetime | ||
from enum import Enum | ||
import itertools | ||
from typing import ( | ||
Any, | ||
|
@@ -116,6 +117,11 @@ | |
|
||
|
||
class ParserBase: | ||
class BadLineHandleMethod(Enum): | ||
ERROR = 0 | ||
WARN = 1 | ||
SKIP = 2 | ||
|
||
_implicit_index: bool = False | ||
_first_chunk: bool | ||
|
||
|
@@ -207,6 +213,30 @@ def __init__(self, kwds): | |
|
||
self.handles: Optional[IOHandles] = None | ||
|
||
# Bad line handling | ||
on_bad_lines = kwds.get("on_bad_lines", "error") | ||
if on_bad_lines == "error": | ||
self.on_bad_lines = self.BadLineHandleMethod.ERROR | ||
elif on_bad_lines == "warn": | ||
self.on_bad_lines = self.BadLineHandleMethod.WARN | ||
elif on_bad_lines == "skip": | ||
self.on_bad_lines = self.BadLineHandleMethod.SKIP | ||
else: | ||
raise ValueError(f"Argument {on_bad_lines} is invalid for on_bad_lines") | ||
# Override on_bad_lines w/ deprecated args for backward compatibility | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't all of these cases show a deprecation warning? L227-238 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like, I said before this is handled by _deprecated_defaults. Ideally _deprecated_defaults wouldn't exist, but as we all know, read_csv is very bloated in terms of API, so its nice to show the deprecation warnings from one place. If you are still unsure, this is tested in this PR here https://github.com/pandas-dev/pandas/pull/40413/files#diff-2f09043040b80b8e52cb8525b43b1653de0ce7d04e0999ca8e0dbe69b05b88faR758-R770 |
||
error_bad_lines = kwds.get("error_bad_lines") | ||
warn_bad_lines = kwds.get("warn_bad_lines") | ||
if error_bad_lines: | ||
self.on_bad_lines = self.BadLineHandleMethod.ERROR | ||
elif warn_bad_lines and error_bad_lines is not None: | ||
# Kinda sketch, but maintain BC in that needs explicit | ||
# error_bad_lines -> False to warn even if warn_bad_lines->True. | ||
# With new default of None, this is necessary. | ||
self.on_bad_lines = self.BadLineHandleMethod.WARN | ||
elif error_bad_lines is False and warn_bad_lines is False: | ||
# Be careful - None evaluates to False | ||
self.on_bad_lines = self.BadLineHandleMethod.SKIP | ||
|
||
def _open_handles(self, src: FilePathOrBuffer, kwds: Dict[str, Any]) -> None: | ||
""" | ||
Let the readers open IOHanldes after they are done with their potential raises. | ||
|
Uh oh!
There was an error while loading. Please reload this page.