Skip to content

Commit cc8a5c2

Browse files
committed
modified tests as requested
1 parent d2f3123 commit cc8a5c2

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

pandas/tests/io/test_excel.py

+31-25
Original file line numberDiff line numberDiff line change
@@ -1859,60 +1859,66 @@ def test_invalid_columns(self):
18591859
write_frame.to_excel(path, 'test1', columns=['C', 'D'])
18601860

18611861
def test_comment_arg(self):
1862+
# Re issue #18735
18621863
# Test the comment argument functionality to read_excel
18631864
with ensure_clean(self.ext) as path:
18641865

18651866
# Create file to read in
1866-
write_frame = DataFrame({'A': ['one', '#one', 'one'],
1867-
'B': ['two', 'two', '#two']})
1868-
write_frame.to_excel(path, 'test_c')
1867+
df = DataFrame({'A': ['one', '#one', 'one'],
1868+
'B': ['two', 'two', '#two']})
1869+
df.to_excel(path, 'test_c')
18691870

18701871
# Read file without comment arg
1871-
read_frame = read_excel(path, 'test_c')
1872-
read_frame_commented = read_excel(path, 'test_c', comment='#')
1873-
tm.assert_class_equal(read_frame, read_frame_commented)
1872+
result1 = read_excel(path, 'test_c')
1873+
result1.iloc[1, 0] = None
1874+
result1.iloc[1, 1] = None
1875+
result1.iloc[2, 1] = None
1876+
result2 = read_excel(path, 'test_c', comment='#')
1877+
tm.assert_frame_equal(result1, result2)
18741878

18751879
def test_comment_default(self):
1880+
# Re issue #18735
18761881
# Test the comment argument default to read_excel
18771882
with ensure_clean(self.ext) as path:
18781883

18791884
# Create file to read in
1880-
write_frame = DataFrame({'A': ['one', '#one', 'one'],
1881-
'B': ['two', 'two', '#two']})
1882-
write_frame.to_excel(path, 'test_c')
1885+
df = DataFrame({'A': ['one', '#one', 'one'],
1886+
'B': ['two', 'two', '#two']})
1887+
df.to_excel(path, 'test_c')
18831888

18841889
# Read file with default and explicit comment=None
1885-
read_frame = read_excel(path, 'test_c')
1886-
read_frame_uncommented = read_excel(path, 'test_c', comment=None)
1887-
tm.assert_frame_equal(read_frame, read_frame_uncommented)
1890+
result1 = read_excel(path, 'test_c')
1891+
result2 = read_excel(path, 'test_c', comment=None)
1892+
tm.assert_frame_equal(result1, result2)
18881893

18891894
def test_comment_used(self):
1895+
# Re issue #18735
18901896
# Test the comment argument is working as expected when used
18911897
with ensure_clean(self.ext) as path:
18921898

18931899
# Create file to read in
1894-
write_frame = DataFrame({'A': ['one', '#one', 'one'],
1895-
'B': ['two', 'two', '#two']})
1896-
write_frame.to_excel(path, 'test_c')
1900+
df = DataFrame({'A': ['one', '#one', 'one'],
1901+
'B': ['two', 'two', '#two']})
1902+
df.to_excel(path, 'test_c')
18971903

18981904
# Test read_frame_comment against manually produced expected output
1899-
read_frame_commented = read_excel(path, 'test_c', comment='#')
1900-
expected = read_excel(path, 'test_c')
1901-
expected.iloc[1, 0] = None
1902-
expected.iloc[1, 1] = None
1903-
expected.iloc[2, 1] = None
1904-
tm.assert_frame_equal(read_frame_commented, expected)
1905+
expected = DataFrame({'A': ['one', None, 'one'],
1906+
'B': ['two', None, None]})
1907+
result = read_excel(path, 'test_c', comment='#')
1908+
tm.assert_frame_equal(result, expected)
19051909

19061910
def test_comment_emptyline(self):
1911+
# Re issue #18735
19071912
# Test that read_excel ignores commented lines at the end of file
19081913
with ensure_clean(self.ext) as path:
19091914

1910-
write_frame = DataFrame({'a': ['1', '#2'], 'b': ['2', '3']})
1911-
write_frame.to_excel(path, index=False)
1915+
df = DataFrame({'a': ['1', '#2'], 'b': ['2', '3']})
1916+
df.to_excel(path, index=False)
19121917

19131918
# Test that all-comment lines at EoF are ignored
1914-
read_frame_short = read_excel(path, comment='#')
1915-
assert (read_frame_short.shape == write_frame.iloc[0:1, :].shape)
1919+
expected = DataFrame({'a': [1], 'b': [2]})
1920+
result = read_excel(path, comment='#')
1921+
tm.assert_frame_equal(result, expected)
19161922

19171923
def test_datetimes(self):
19181924

0 commit comments

Comments
 (0)