@@ -1863,60 +1863,66 @@ def test_invalid_columns(self):
1863
1863
write_frame .to_excel (path , 'test1' , columns = ['C' , 'D' ])
1864
1864
1865
1865
def test_comment_arg (self ):
1866
+ # Re issue #18735
1866
1867
# Test the comment argument functionality to read_excel
1867
1868
with ensure_clean (self .ext ) as path :
1868
1869
1869
1870
# 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' )
1873
1874
1874
1875
# 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 )
1878
1882
1879
1883
def test_comment_default (self ):
1884
+ # Re issue #18735
1880
1885
# Test the comment argument default to read_excel
1881
1886
with ensure_clean (self .ext ) as path :
1882
1887
1883
1888
# 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' )
1887
1892
1888
1893
# 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 )
1892
1897
1893
1898
def test_comment_used (self ):
1899
+ # Re issue #18735
1894
1900
# Test the comment argument is working as expected when used
1895
1901
with ensure_clean (self .ext ) as path :
1896
1902
1897
1903
# 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' )
1901
1907
1902
1908
# 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 )
1909
1913
1910
1914
def test_comment_emptyline (self ):
1915
+ # Re issue #18735
1911
1916
# Test that read_excel ignores commented lines at the end of file
1912
1917
with ensure_clean (self .ext ) as path :
1913
1918
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 )
1916
1921
1917
1922
# 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 )
1920
1926
1921
1927
def test_datetimes (self ):
1922
1928
0 commit comments