Skip to content

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

Merged
merged 2 commits into from
Aug 8, 2025
Merged

Conversation

ngoldbaum
Copy link
Contributor

@ngoldbaum ngoldbaum commented Aug 8, 2025

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 regular open 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.

@@ -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"])
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 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:
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 changed it from "wb" to "w" because I think the "b" here is a bug (bytes and utf-8???)

@mroeschke mroeschke added this to the 3.0 milestone Aug 8, 2025
@mroeschke mroeschke added the Testing pandas testing functions or related to the test suite label Aug 8, 2025
@mroeschke mroeschke merged commit 25d63e8 into pandas-dev:main Aug 8, 2025
47 checks passed
@mroeschke
Copy link
Member

Thanks @ngoldbaum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants