Skip to content
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

BUG: #57954 encoding ignored for filelike #57968

Merged

Conversation

dontgoto
Copy link
Contributor

@dontgoto dontgoto commented Mar 22, 2024

@dontgoto dontgoto changed the title #57954 encoding ignored for filelike BUG: #57954 encoding ignored for filelike Mar 22, 2024
@@ -1485,6 +1485,17 @@ def _make_engine(
"pyarrow": ArrowParserWrapper,
"python-fwf": FixedWidthFieldParser,
}

file_encoding = getattr(f, "encoding", None)
Copy link
Member

Choose a reason for hiding this comment

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

This check might be better in _check_file_or_buffer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like your suggestion, but trying that out the type checking throws errors. None of the annotated classes in _make_engine guarantee an encoding attribute, so the getattr check would be necessary here anyway at least for the type checker.

Copy link
Member

Choose a reason for hiding this comment

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

It's OK adding typing ignores as needed

@mroeschke mroeschke added Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv labels Mar 25, 2024
@mroeschke mroeschke added this to the 3.0 milestone Mar 28, 2024
@mroeschke mroeschke merged commit b86eb99 into pandas-dev:main Mar 28, 2024
46 checks passed
@mroeschke
Copy link
Member

Thanks @dontgoto

@dontgoto dontgoto deleted the #57954_encoding_ignored_for_filelike branch March 28, 2024 23:30
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
* add exception when encodings exist and do not match

* add exception when encodings exist and do not match

* add test for mismatching encodings warning

* add test for mismatching encodings warning

* add encoding for python 3.10+

* move to _check_file; invert var and condition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas IO CSV read_csv, to_csv
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: encoding is **silently** ignored for read_csv on FileLike objects
2 participants