Skip to content

BUG: Add type check for encoding_errors in pd.read_csv #59075

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

Merged
merged 19 commits into from
Jun 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pandas/io/parsers/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,13 @@ def _make_engine(
raise ValueError(
f"Unknown engine: {engine} (valid options are {mapping.keys()})"
)

errors = self.options.get("encoding_errors", "strict")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this logic into _read?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I have moved it into _read

if not isinstance(errors, str) and errors is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not isinstance(errors, str) and errors is not None:
if not isinstance(errors, str):

raise ValueError(
f"encoding_errors must be a string, got {type(errors).__name__}"
)

if not isinstance(f, list):
# open file here
is_text = True
Expand All @@ -1437,7 +1444,7 @@ def _make_engine(
compression=self.options.get("compression", None),
memory_map=self.options.get("memory_map", False),
is_text=is_text,
errors=self.options.get("encoding_errors", "strict"),
errors=errors,
storage_options=self.options.get("storage_options", None),
)
assert self.handles is not None
Expand Down
Loading