Skip to content

Commit 11de44a

Browse files
committed
restore
1 parent 4ff00b7 commit 11de44a

File tree

137 files changed

+24870
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+24870
-0
lines changed

pandas/tests/io/excel/__init__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import pytest
2+
3+
from pandas.compat._optional import (
4+
get_version,
5+
import_optional_dependency,
6+
)
7+
8+
from pandas.util.version import Version
9+
10+
pytestmark = [
11+
pytest.mark.filterwarnings(
12+
# Looks like tree.getiterator is deprecated in favor of tree.iter
13+
"ignore:This method will be removed in future versions:"
14+
"PendingDeprecationWarning"
15+
),
16+
pytest.mark.filterwarnings(
17+
"ignore:This method will be removed in future versions:DeprecationWarning"
18+
),
19+
# GH 26552
20+
pytest.mark.filterwarnings(
21+
"ignore:As the xlwt package is no longer maintained:FutureWarning"
22+
),
23+
# GH 38571
24+
pytest.mark.filterwarnings(
25+
"ignore:.*In xlrd >= 2.0, only the xls format is supported:FutureWarning"
26+
),
27+
]
28+
29+
30+
if import_optional_dependency("xlrd", errors="ignore") is None:
31+
xlrd_version = None
32+
else:
33+
import xlrd
34+
35+
xlrd_version = Version(get_version(xlrd))

pandas/tests/io/excel/conftest.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import pytest
2+
3+
import pandas.util._test_decorators as td
4+
5+
import pandas._testing as tm
6+
7+
from pandas.io.parsers import read_csv
8+
9+
10+
@pytest.fixture
11+
def frame(float_frame):
12+
"""
13+
Returns the first ten items in fixture "float_frame".
14+
"""
15+
return float_frame[:10]
16+
17+
18+
@pytest.fixture
19+
def tsframe():
20+
return tm.makeTimeDataFrame()[:5]
21+
22+
23+
@pytest.fixture(params=[True, False])
24+
def merge_cells(request):
25+
return request.param
26+
27+
28+
@pytest.fixture
29+
def df_ref(datapath):
30+
"""
31+
Obtain the reference data from read_csv with the Python engine.
32+
"""
33+
filepath = datapath("io", "data", "csv", "test1.csv")
34+
df_ref = read_csv(filepath, index_col=0, parse_dates=True, engine="python")
35+
return df_ref
36+
37+
38+
@pytest.fixture(params=[".xls", ".xlsx", ".xlsm", ".ods", ".xlsb"])
39+
def read_ext(request):
40+
"""
41+
Valid extensions for reading Excel files.
42+
"""
43+
return request.param
44+
45+
46+
@pytest.fixture(autouse=True)
47+
def check_for_file_leaks():
48+
"""
49+
Fixture to run around every test to ensure that we are not leaking files.
50+
51+
See also
52+
--------
53+
_test_decorators.check_file_leaks
54+
"""
55+
# GH#30162
56+
psutil = td.safe_import("psutil")
57+
if not psutil:
58+
yield
59+
60+
else:
61+
proc = psutil.Process()
62+
flist = proc.open_files()
63+
yield
64+
flist2 = proc.open_files()
65+
assert flist == flist2

pandas/tests/io/excel/test_odf.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import functools
2+
3+
import numpy as np
4+
import pytest
5+
6+
import pandas as pd
7+
import pandas._testing as tm
8+
9+
pytest.importorskip("odf")
10+
11+
12+
@pytest.fixture(autouse=True)
13+
def cd_and_set_engine(monkeypatch, datapath):
14+
func = functools.partial(pd.read_excel, engine="odf")
15+
monkeypatch.setattr(pd, "read_excel", func)
16+
monkeypatch.chdir(datapath("io", "data", "excel"))
17+
18+
19+
def test_read_invalid_types_raises():
20+
# the invalid_value_type.ods required manually editing
21+
# of the included content.xml file
22+
with pytest.raises(ValueError, match="Unrecognized type awesome_new_type"):
23+
pd.read_excel("invalid_value_type.ods")
24+
25+
26+
def test_read_writer_table():
27+
# Also test reading tables from an text OpenDocument file
28+
# (.odt)
29+
index = pd.Index(["Row 1", "Row 2", "Row 3"], name="Header")
30+
expected = pd.DataFrame(
31+
[[1, np.nan, 7], [2, np.nan, 8], [3, np.nan, 9]],
32+
index=index,
33+
columns=["Column 1", "Unnamed: 2", "Column 3"],
34+
)
35+
36+
result = pd.read_excel("writertable.odt", sheet_name="Table1", index_col=0)
37+
38+
tm.assert_frame_equal(result, expected)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import re
2+
3+
import pytest
4+
5+
import pandas._testing as tm
6+
7+
from pandas.io.excel import ExcelWriter
8+
9+
odf = pytest.importorskip("odf")
10+
11+
pytestmark = pytest.mark.parametrize("ext", [".ods"])
12+
13+
14+
def test_write_append_mode_raises(ext):
15+
msg = "Append mode is not supported with odf!"
16+
17+
with tm.ensure_clean(ext) as f:
18+
with pytest.raises(ValueError, match=msg):
19+
ExcelWriter(f, engine="odf", mode="a")
20+
21+
22+
def test_kwargs(ext):
23+
# GH 42286
24+
# GH 43445
25+
# test for error: OpenDocumentSpreadsheet does not accept any arguments
26+
kwargs = {"kwarg": 1}
27+
with tm.ensure_clean(ext) as f:
28+
msg = re.escape("Use of **kwargs is deprecated")
29+
error = re.escape(
30+
"OpenDocumentSpreadsheet() got an unexpected keyword argument 'kwarg'"
31+
)
32+
with pytest.raises(
33+
TypeError,
34+
match=error,
35+
):
36+
with tm.assert_produces_warning(FutureWarning, match=msg):
37+
with ExcelWriter(f, engine="odf", **kwargs) as _:
38+
pass
39+
40+
41+
@pytest.mark.parametrize("engine_kwargs", [None, {"kwarg": 1}])
42+
def test_engine_kwargs(ext, engine_kwargs):
43+
# GH 42286
44+
# GH 43445
45+
# test for error: OpenDocumentSpreadsheet does not accept any arguments
46+
with tm.ensure_clean(ext) as f:
47+
if engine_kwargs is not None:
48+
error = re.escape(
49+
"OpenDocumentSpreadsheet() got an unexpected keyword argument 'kwarg'"
50+
)
51+
with pytest.raises(
52+
TypeError,
53+
match=error,
54+
):
55+
ExcelWriter(f, engine="odf", engine_kwargs=engine_kwargs)
56+
else:
57+
with ExcelWriter(f, engine="odf", engine_kwargs=engine_kwargs) as _:
58+
pass

0 commit comments

Comments
 (0)