Skip to content

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
"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
@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

2 participants