Skip to content

Commit afc3ec3

Browse files
committed
modified tests as requested
1 parent 079b60f commit afc3ec3

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

pandas/tests/io/test_excel.py

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,60 +1863,66 @@ def test_invalid_columns(self):
18631863
write_frame.to_excel(path, 'test1', columns=['C', 'D'])
18641864

18651865
def test_comment_arg(self):
1866+
# Re issue #18735
18661867
# Test the comment argument functionality to read_excel
18671868
with ensure_clean(self.ext) as path:
18681869

18691870
# Create file to read in
1870-
write_frame = DataFrame({'A': ['one', '#one', 'one'],
1871-
'B': ['two', 'two', '#two']})
1872-
write_frame.to_excel(path, 'test_c')
1871+
df = DataFrame({'A': ['one', '#one', 'one'],
1872+
'B': ['two', 'two', '#two']})
1873+
df.to_excel(path, 'test_c')
18731874

18741875
# Read file without comment arg
1875-
read_frame = read_excel(path, 'test_c')
1876-
read_frame_commented = read_excel(path, 'test_c', comment='#')
1877-
tm.assert_class_equal(read_frame, read_frame_commented)
1876+
result1 = read_excel(path, 'test_c')
1877+
result1.iloc[1, 0] = None
1878+
result1.iloc[1, 1] = None
1879+
result1.iloc[2, 1] = None
1880+
result2 = read_excel(path, 'test_c', comment='#')
1881+
tm.assert_frame_equal(result1, result2)
18781882

18791883
def test_comment_default(self):
1884+
# Re issue #18735
18801885
# Test the comment argument default to read_excel
18811886
with ensure_clean(self.ext) as path:
18821887

18831888
# Create file to read in
1884-
write_frame = DataFrame({'A': ['one', '#one', 'one'],
1885-
'B': ['two', 'two', '#two']})
1886-
write_frame.to_excel(path, 'test_c')
1889+
df = DataFrame({'A': ['one', '#one', 'one'],
1890+
'B': ['two', 'two', '#two']})
1891+
df.to_excel(path, 'test_c')
18871892

18881893
# Read file with default and explicit comment=None
1889-
read_frame = read_excel(path, 'test_c')
1890-
read_frame_uncommented = read_excel(path, 'test_c', comment=None)
1891-
tm.assert_frame_equal(read_frame, read_frame_uncommented)
1894+
result1 = read_excel(path, 'test_c')
1895+
result2 = read_excel(path, 'test_c', comment=None)
1896+
tm.assert_frame_equal(result1, result2)
18921897

18931898
def test_comment_used(self):
1899+
# Re issue #18735
18941900
# Test the comment argument is working as expected when used
18951901
with ensure_clean(self.ext) as path:
18961902

18971903
# Create file to read in
1898-
write_frame = DataFrame({'A': ['one', '#one', 'one'],
1899-
'B': ['two', 'two', '#two']})
1900-
write_frame.to_excel(path, 'test_c')
1904+
df = DataFrame({'A': ['one', '#one', 'one'],
1905+
'B': ['two', 'two', '#two']})
1906+
df.to_excel(path, 'test_c')
19011907

19021908
# Test read_frame_comment against manually produced expected output
1903-
read_frame_commented = read_excel(path, 'test_c', comment='#')
1904-
expected = read_excel(path, 'test_c')
1905-
expected.iloc[1, 0] = None
1906-
expected.iloc[1, 1] = None
1907-
expected.iloc[2, 1] = None
1908-
tm.assert_frame_equal(read_frame_commented, expected)
1909+
expected = DataFrame({'A': ['one', None, 'one'],
1910+
'B': ['two', None, None]})
1911+
result = read_excel(path, 'test_c', comment='#')
1912+
tm.assert_frame_equal(result, expected)
19091913

19101914
def test_comment_emptyline(self):
1915+
# Re issue #18735
19111916
# Test that read_excel ignores commented lines at the end of file
19121917
with ensure_clean(self.ext) as path:
19131918

1914-
write_frame = DataFrame({'a': ['1', '#2'], 'b': ['2', '3']})
1915-
write_frame.to_excel(path, index=False)
1919+
df = DataFrame({'a': ['1', '#2'], 'b': ['2', '3']})
1920+
df.to_excel(path, index=False)
19161921

19171922
# Test that all-comment lines at EoF are ignored
1918-
read_frame_short = read_excel(path, comment='#')
1919-
assert (read_frame_short.shape == write_frame.iloc[0:1, :].shape)
1923+
expected = DataFrame({'a': [1], 'b': [2]})
1924+
result = read_excel(path, comment='#')
1925+
tm.assert_frame_equal(result, expected)
19201926

19211927
def test_datetimes(self):
19221928

0 commit comments

Comments
 (0)