Skip to content

Commit 2f917e8

Browse files
author
Chang She
committed
BUG: fixed empty case #1835
1 parent 513267d commit 2f917e8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pandas/io/parsers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,17 +801,21 @@ def get_chunk(self, rows=None):
801801
# done with first read, next time raise StopIteration
802802
self._first_chunk = False
803803

804+
columns = list(self.orig_columns)
804805
if len(content) == 0: # pragma: no cover
805806
if self.index_col is not None:
806807
if np.isscalar(self.index_col):
807808
index = Index([], name=self.index_name)
809+
columns.pop(self.index_col)
808810
else:
809811
index = MultiIndex.from_arrays([[]] * len(self.index_col),
810812
names=self.index_name)
813+
for n in self.index_col:
814+
columns.pop(n)
811815
else:
812816
index = Index([])
813817

814-
return DataFrame(index=index, columns=self.columns)
818+
return DataFrame(index=index, columns=columns)
815819

816820
alldata = self._rows_to_cols(content)
817821
data = self._exclude_implicit_index(alldata)
@@ -824,7 +828,6 @@ def get_chunk(self, rows=None):
824828

825829
data = _convert_to_ndarrays(data, self.na_values, self.verbose)
826830

827-
columns = list(self.orig_columns)
828831
if self.parse_dates is not None:
829832
data, columns = self._process_date_conversion(data)
830833

0 commit comments

Comments
 (0)