File tree 3 files changed +23
-2
lines changed
3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -57,5 +57,6 @@ Bug Fixes
57
57
- Bug in ``DataFrame.to_json`` where ``lines=True`` and a value contained a ``}`` character (:issue:`14391`)
58
58
- Bug in ``df.groupby`` causing an ``AttributeError`` when grouping a single index frame by a column and the index level (:issue`14327`)
59
59
- Bug in ``df.groupby`` where ``TypeError`` raised when ``pd.Grouper(key=...)`` is passed in a list (:issue:`14334`)
60
+ - Bug in ``pd.read_csv`` where reading files fails if the number of headers is equal to the number of lines in the file (:issue:`14515`)
60
61
- Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns``
61
62
is not scalar and ``values`` is not specified (:issue:`14380`)
Original file line number Diff line number Diff line change @@ -606,6 +606,24 @@ def test_multi_index_no_level_names(self):
606
606
expected = self .read_csv (StringIO (data ), index_col = [1 , 0 ])
607
607
tm .assert_frame_equal (df , expected , check_names = False )
608
608
609
+ def test_multi_index_blank_df (self ):
610
+ # GH 14545
611
+ data = """a,b
612
+ """
613
+ df = self .read_csv (StringIO (data ), header = [0 ])
614
+ expected = DataFrame (columns = [('a' ),('b' )])
615
+ tm .assert_frame_equal (df , expected )
616
+ expected_csv = expected .to_csv ()
617
+ round_trip = self .read_csv (StringIO (expected_csv ))
618
+ tm .assert_frame_equal (expected , round_trip )
619
+
620
+ data_multiline = """a,b
621
+ c,d
622
+ """
623
+ df2 = self .read_csv (StringIO (data_multiline ), header = [0 ,1 ])
624
+ expected2 = DataFrame (columns = [('a' , 'c' ), ('b' , 'd' )])
625
+ tm .assert_frame_equal (df2 , expected2 )
626
+
609
627
def test_no_unnamed_index (self ):
610
628
data = """ id c0 c1 c2
611
629
0 1 0 a b
Original file line number Diff line number Diff line change @@ -717,7 +717,9 @@ cdef class TextReader:
717
717
start = self .parser.line_start[0 ]
718
718
719
719
# e.g., if header=3 and file only has 2 lines
720
- elif self .parser.lines < hr + 1 :
720
+ if (self .parser.lines < hr + 1
721
+ and not isinstance (self .orig_header, list )) or (
722
+ self .parser.lines < hr):
721
723
msg = self .orig_header
722
724
if isinstance (msg, list ):
723
725
msg = " [%s ], len of %d ," % (
@@ -940,7 +942,7 @@ cdef class TextReader:
940
942
raise_parser_error(' Error tokenizing data' , self .parser)
941
943
footer = self .skipfooter
942
944
943
- if self .parser_start = = self .parser.lines:
945
+ if self .parser_start > = self .parser.lines:
944
946
raise StopIteration
945
947
self ._end_clock(' Tokenization' )
946
948
You can’t perform that action at this time.
0 commit comments