Skip to content

Commit 8302fd7

Browse files
committed
Added test_odf
1 parent 735e2b4 commit 8302fd7

File tree

1 file changed

+47
-32
lines changed

1 file changed

+47
-32
lines changed

pandas/tests/io/excel/test_odf.py

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
odf = pytest.importorskip("odf")
1+
from collections import OrderedDict
22

3+
import numpy as np
4+
import pytest
35

4-
def test_get_sheet(self):
6+
import pandas as pd
7+
import pandas.util.testing as tm
8+
9+
pytest.importorskip("odf")
10+
11+
12+
def test_get_sheet(datapath):
513
from pandas.io.excel._odfreader import ODFReader
614

7-
pth = os.path.join(self.dirpath, 'datatypes.ods')
15+
pth = datapath("io", "data", "datatypes.ods")
816
book = ODFReader(pth)
917

1018
assert len(book.sheet_names) == 1
1119
assert book.sheet_names == ['Sheet1']
1220

13-
def test_get_sheet_raises(self):
21+
22+
def test_get_sheet_raises(datapath):
1423
from pandas.io.excel._odfreader import ODFReader
1524

16-
pth = os.path.join(self.dirpath, 'datatypes.ods')
25+
pth = datapath("io", "data", 'datatypes.ods')
1726
book = ODFReader(pth)
1827

1928
with pytest.raises(ValueError):
@@ -25,11 +34,12 @@ def test_get_sheet_raises(self):
2534
with pytest.raises(IndexError):
2635
book.get_sheet_by_index(-33)
2736

28-
def test_read_types(self):
29-
sheet = self.get_exceldf(
30-
'datatypes', '.ods', header=None, engine='odf')
3137

32-
expected = DataFrame(
38+
def test_read_types(datapath):
39+
path = datapath("io", "data", "datatypes.ods")
40+
sheet = pd.read_excel(path, header=None, engine='odf')
41+
42+
expected = pd.DataFrame(
3343
[[1.0],
3444
[1.25],
3545
['a'],
@@ -43,32 +53,34 @@ def test_read_types(self):
4353
['UBERON:0002101']])
4454
tm.assert_equal(sheet, expected)
4555

46-
def test_read_invalid_types_raises(self):
56+
57+
def test_read_invalid_types_raises(datapath):
4758
# the invalid_value_type.ods required manually editing
4859
# of the included content.xml file
60+
path = datapath("io", "data", "invalid_value_type.ods")
4961
with pytest.raises(ValueError,
5062
match="Unrecognized type awesome_new_type"):
51-
self.get_exceldf(
52-
'invalid_value_type', '.ods', header=None, engine='odf')
63+
pd.read_excel(path, header=None, engine='odf')
5364

54-
def test_read_lower_diagonal(self):
65+
66+
def test_read_lower_diagonal(datapath):
5567
# Make sure we can parse:
5668
# 1
5769
# 2 3
5870
# 4 5 6
5971
# 7 8 9 10
60-
61-
sheet = self.get_exceldf(
62-
'lowerdiagonal', '.ods', 'Sheet1',
63-
index_col=None, header=None, engine='odf')
72+
path = datapath("io", "data", "lowerdiagonal.ods")
73+
sheet = pd.read_excel(path, 'Sheet1',
74+
index_col=None, header=None, engine='odf')
6475

6576
assert sheet.shape == (4, 4)
6677

67-
def test_read_headers(self):
68-
sheet = self.get_exceldf(
69-
'headers', '.ods', 'Sheet1', index_col=0, engine='odf')
7078

71-
expected = DataFrame.from_dict(OrderedDict([
79+
def test_read_headers(datapath):
80+
path = datapath("io", "data", "headers.ods")
81+
sheet = pd.read_excel(path, 'Sheet1', index_col=0, engine='odf')
82+
83+
expected = pd.DataFrame.from_dict(OrderedDict([
7284
("Header", ["Row 1", "Row 2"]),
7385
("Column 1", [1.0, 2.0]),
7486
("Column 2", [3.0, 4.0]),
@@ -84,18 +96,19 @@ def test_read_headers(self):
8496
for value in sheet[name]:
8597
assert pd.isnull(value)
8698

87-
def test_read_writer_table(self):
99+
100+
def test_read_writer_table(datapath):
88101
# Also test reading tables from an text OpenDocument file
89102
# (.odt)
90103

91-
table = self.get_exceldf(
92-
'writertable', '.odt', 'Table1', index_col=0, engine='odf')
104+
path = datapath("io", "data", "writertable.odt")
105+
table = pd.read_excel(path, 'Table1', index_col=0, engine='odf')
93106

94107
assert table.shape == (3, 3)
95-
expected = DataFrame.from_dict(OrderedDict([
108+
expected = pd.DataFrame.from_dict(OrderedDict([
96109
("Header", ["Row 1", "Row 2", "Row 3"]),
97110
("Column 1", [1.0, 2.0, 3.0]),
98-
("Unnamed: 2", [nan, nan, nan]),
111+
("Unnamed: 2", [np.nan, np.nan, np.nan]),
99112
("Column 3", [7.0, 8.0, 9.0])]))
100113
expected.set_index("Header", inplace=True)
101114
columns = ["Column 1", "Column 3"]
@@ -105,18 +118,20 @@ def test_read_writer_table(self):
105118
for i in range(3):
106119
assert pd.isnull(table["Unnamed: 2"][i])
107120

108-
def test_blank_row_repeat(self):
109-
table = self.get_exceldf(
110-
'blank-row-repeat', '.ods', 'Value', engine='odf')
121+
122+
def test_blank_row_repeat(datapath):
123+
path = datapath("io", "data", "blank-row-repeat.ods")
124+
table = pd.read_excel(path, 'Value', engine='odf')
111125

112126
assert table.shape == (14, 2)
113127
assert table['value'][7] == 9.0
114128
assert pd.isnull(table['value'][8])
115129
assert not pd.isnull(table['value'][11])
116130

117-
def test_runlengthencoding(self):
118-
sheet = self.get_exceldf(
119-
'runlengthencoding', '.ods', 'Sheet1', header=None, engine='odf')
131+
132+
def test_runlengthencoding(datapath):
133+
path = datapath("io", "data", "runlengthencoding.ods")
134+
sheet = pd.read_excel(path, 'Sheet1', header=None, engine='odf')
120135
assert sheet.shape == (5, 3)
121136
# check by column, not by row.
122137
assert list(sheet[0]) == [1.0, 1.0, 2.0, 2.0, 2.0]

0 commit comments

Comments
 (0)