@@ -1859,60 +1859,66 @@ def test_invalid_columns(self):
1859
1859
write_frame .to_excel (path , 'test1' , columns = ['C' , 'D' ])
1860
1860
1861
1861
def test_comment_arg (self ):
1862
+ # Re issue #18735
1862
1863
# Test the comment argument functionality to read_excel
1863
1864
with ensure_clean (self .ext ) as path :
1864
1865
1865
1866
# 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' )
1869
1870
1870
1871
# 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 )
1874
1878
1875
1879
def test_comment_default (self ):
1880
+ # Re issue #18735
1876
1881
# Test the comment argument default to read_excel
1877
1882
with ensure_clean (self .ext ) as path :
1878
1883
1879
1884
# 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' )
1883
1888
1884
1889
# 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 )
1888
1893
1889
1894
def test_comment_used (self ):
1895
+ # Re issue #18735
1890
1896
# Test the comment argument is working as expected when used
1891
1897
with ensure_clean (self .ext ) as path :
1892
1898
1893
1899
# 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' )
1897
1903
1898
1904
# 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 )
1905
1909
1906
1910
def test_comment_emptyline (self ):
1911
+ # Re issue #18735
1907
1912
# Test that read_excel ignores commented lines at the end of file
1908
1913
with ensure_clean (self .ext ) as path :
1909
1914
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 )
1912
1917
1913
1918
# 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 )
1916
1922
1917
1923
def test_datetimes (self ):
1918
1924
0 commit comments