-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
STYLE: specify encodings when opening files #52999
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
Conversation
KetuPatel806
commented
Apr 29, 2023
•
edited
Loading
edited
- closes STYLE: specify encodings when opening files #52963 #52997 (Replace STYLE: specify encodings when opening files #52963 #52997 with the GitHub issue number)
- Tests added and passed if fixing a bug or adding a new feature
- All code checks passed.
- Added type annotations to new arguments/methods/functions.
let's stick to one PR, please don't open a new one which does the same thing same comments from #52997, please address them |
This is my first PR so I was making mistake next time i was more carefull for making PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getting there 💪
could you please:
- remove
b/.pre-commit-config.yaml
- run
pre-commit
on the rest of the files you've modified?
pre-commit run --from-ref=upstream/main --to-ref=HEAD --all-files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this is it, thanks @KetuPatel806 !
pandas/_testing/contexts.py
Outdated
@@ -126,7 +126,7 @@ def ensure_clean( | |||
handle_or_str: str | IO = str(path) | |||
if return_filelike: | |||
kwargs.setdefault("mode", "w+b") | |||
handle_or_str = open(path, **kwargs) | |||
handle_or_str = open(path, **kwargs, encoding="utf-8") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apologies, looks like some tests are failing here due to
TypeError: io.open() got multiple values for keyword argument 'encoding'
we may have to do something like
handle_or_str = open(path, encoding=kwargs.get('encoding', None), **{key: value for key, value in kwargs.items() if key != 'encoding'})
, could you try this please and see if it fixes the failing tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok,I'll do it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it run the pre-commit command and i'll commit it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getting closer
pandas/tests/io/xml/test_xml.py
Outdated
@@ -1444,7 +1444,7 @@ def test_file_io_iterparse(datapath, parser, mode): | |||
filename = datapath("io", "data", "xml", "books.xml") | |||
|
|||
funcIO = StringIO if mode == "r" else BytesIO | |||
with open(filename, mode) as f: | |||
with open(filename, mode, encoding="utf-8") as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one's causing test failures - could we do encoding="utf-8" if mode=="r" else None
?
pandas/tests/io/xml/test_xml.py
Outdated
@@ -1444,7 +1444,7 @@ def test_file_io_iterparse(datapath, parser, mode): | |||
filename = datapath("io", "data", "xml", "books.xml") | |||
|
|||
funcIO = StringIO if mode == "r" else BytesIO | |||
with open(filename, mode) as f: | |||
with open(filename, mode, encoding="utf-8" if mode=="r" else None) as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still gonna have to run pre-commit
on the files you've modifed though ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was run it. it passed all of the hooks. only black (hook) failed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's still some test failures
it may be worth parametrising over both mode
and encoding
. either that, or putting similar encoding='utf-8' if mode=='r' else None
in the failing tests
pandas/tests/io/xml/test_xml.py
Outdated
with open(filename, mode) as f: | ||
with open( | ||
filename, | ||
mode="utf-8" if mode == "r" else None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to change encoding
, not mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just keep mode as it is
this is close, a few tests left. would be great if you could finish it up, else I can add a commit on Tuesday and push this over the finish line |
can i fixes that cases or you push this over the final line??? |
feel free to fix |
can you refer that test cases so i'll fix it? |
check the failing tests in the CI logs |
you'll need to fix the tests (in addition to merging upstream/main) to get this passing |
i have check the circle ci to find the error and i tired on a local to fix it. |
i try to fix read Binary mode error but if i remove the encoding then pre-commit command does not work it give me error massage called as "unspecified encoding" |
i thought it finish it up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be good, thanks @KetuPatel806 !
* Changes Confirmed * Encoding Completed * Spaces Are Completed * Pre-ccommit manually completed * b.pre-commit removed * Final Commit * Some Changed reflected * test_xml Updated * Pre-commit check passed * Mode changed in xml file * mode reverted * Try to fix errors * error-checks * Fix Some errors * Unspecified-encodingFixed * final commited * simplify --------- Co-authored-by: MarcoGorelli <>
* Changes Confirmed * Encoding Completed * Spaces Are Completed * Pre-ccommit manually completed * b.pre-commit removed * Final Commit * Some Changed reflected * test_xml Updated * Pre-commit check passed * Mode changed in xml file * mode reverted * Try to fix errors * error-checks * Fix Some errors * Unspecified-encodingFixed * final commited * simplify --------- Co-authored-by: MarcoGorelli <>