Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pandas/tests/io/formats/test_to_latex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import codecs
from datetime import datetime
from textwrap import dedent

Expand Down Expand Up @@ -42,15 +41,15 @@ def test_to_latex_to_file_utf8_with_encoding(self):
df = DataFrame([["au\xdfgangen"]])
with tm.ensure_clean("test.tex") as path:
df.to_latex(path, encoding="utf-8")
with codecs.open(path, "r", encoding="utf-8") as f:
with open(path, encoding="utf-8") as f:
assert df.to_latex() == f.read()

def test_to_latex_to_file_utf8_without_encoding(self):
# test with utf-8 without encoding option
df = DataFrame([["au\xdfgangen"]])
with tm.ensure_clean("test.tex") as path:
df.to_latex(path)
with codecs.open(path, "r", encoding="utf-8") as f:
with open(path, encoding="utf-8") as f:
assert df.to_latex() == f.read()

def test_to_latex_tabular_with_index(self):
Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/io/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,19 +513,18 @@ def test_is_fsspec_url():
assert icom.is_fsspec_url("RFC-3986+compliant.spec://something")


@pytest.mark.parametrize("encoding", [None, "utf-8"])
@pytest.mark.parametrize("format", ["csv", "json"])
def test_codecs_encoding(encoding, format):
def test_codecs_encoding(format):
# GH39247
expected = pd.DataFrame(
1.1 * np.arange(120).reshape((30, 4)),
columns=pd.Index(list("ABCD")),
index=pd.Index([f"i-{i}" for i in range(30)]),
)
with tm.ensure_clean() as path:
with codecs.open(path, mode="w", encoding=encoding) as handle:
with open(path, mode="w", encoding="utf-8") as handle:
getattr(expected, f"to_{format}")(handle)
with codecs.open(path, mode="r", encoding=encoding) as handle:
with open(path, encoding="utf-8") as handle:
if format == "csv":
df = pd.read_csv(handle, index_col=0)
else:
Expand Down
3 changes: 1 addition & 2 deletions pandas/util/_print_versions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import codecs
import json
import locale
import os
Expand Down Expand Up @@ -139,7 +138,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:
json.dump(j, f, indent=2)

else:
Expand Down
Loading