-
-
Notifications
You must be signed in to change notification settings - Fork 18.9k
MNT: migrate from codecs.open to open #62073
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
@@ -513,19 +513,18 @@ def test_is_fsspec_url_chained(): | |||
assert not icom.is_fsspec_url("filecache::://pandas/test.csv") | |||
|
|||
|
|||
@pytest.mark.parametrize("encoding", [None, "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.
I could also keep testing this but CPython warns about using open(..., encoding=None)
: EncodingWarning: 'encoding' argument not specified
. In this case we are explicitly specifying None
but I don't think CPython can tell the difference.
@@ -143,7 +142,7 @@ def show_versions(as_json: str | bool = False) -> None: | |||
sys.stdout.writelines(json.dumps(j, indent=2)) | |||
else: | |||
assert isinstance(as_json, str) # needed for mypy | |||
with codecs.open(as_json, "wb", encoding="utf8") as f: | |||
with open(as_json, "w", 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.
I changed it from "wb" to "w" because I think the "b" here is a bug (bytes and utf-8???)
Thanks @ngoldbaum |
c.f. #61950, towards supporting Python 3.14
See the 3.14 deprecations and python/cpython#133036 for more details.
There is one spot that was nontrivial - the use in
pandas.util._print_versions
I think was buggy - it wanted to write a file in bytes mode and also specified an encoding.codecs.open
didn't blink at this but regularopen
is more restrictive. I think what I updated it to is correct and this is a latent bug, probably introduced a long time ago in the 2->3 transition.doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.