Skip to content
Closed
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
24 changes: 20 additions & 4 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

from pandas.compat import (
IS64,
PY310,
PY311,
is_numpy_dev,
is_platform_windows,
)
import pandas.util._test_decorators as td
Expand Down Expand Up @@ -3384,10 +3387,23 @@ def test_filepath_or_buffer_arg(
):
getattr(df, method)(buf=filepath_or_buffer, encoding=encoding)
elif encoding == "foo":
expected_warning = FutureWarning if method == "to_latex" else None
with tm.assert_produces_warning(expected_warning):
with pytest.raises(LookupError, match="unknown encoding"):
getattr(df, method)(buf=filepath_or_buffer, encoding=encoding)
if (
method == "to_string"
and data == "abc"
and filepath_or_buffer_id == "string"
and PY310
and not PY311
and not is_numpy_dev
):
# raises importwarning _SixMetaPathImporter.find_spec
with tm.assert_produces_warning(ImportWarning, check_stacklevel=False):
with pytest.raises(LookupError, match="unknown encoding"):
getattr(df, method)(buf=filepath_or_buffer, encoding=encoding)
else:
expected_warning = FutureWarning if method == "to_latex" else None
with tm.assert_produces_warning(expected_warning):
with pytest.raises(LookupError, match="unknown encoding"):
getattr(df, method)(buf=filepath_or_buffer, encoding=encoding)
else:
expected = getattr(df, method)()
getattr(df, method)(buf=filepath_or_buffer, encoding=encoding)
Expand Down