Skip to content

Commit 9015e43

Browse files
committed
Merge branch 'fix_empty_open' of https://github.com/bquistorff/pandas into bquistorff-fix_empty_open
Conflicts: doc/source/v0.14.1.txt
2 parents 7ef4efa + f5a1113 commit 9015e43

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

doc/source/v0.14.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ Bug Fixes
219219
(:issue:`7352`)
220220
- Bug where ``nanops._has_infs`` doesn't work with many dtypes
221221
(:issue:`7357`)
222+
- Bug in ``StataReader.data`` where reading a 0-observation dta failed (:issue:`7369`)
222223

223224

224225

pandas/io/stata.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,10 @@ def data(self, convert_dates=True, convert_categoricals=True, index=None):
852852
if convert_categoricals:
853853
self._read_value_labels()
854854

855-
data = DataFrame(data, columns=self.varlist, index=index)
855+
if len(data)==0:
856+
data = DataFrame(columns=self.varlist, index=index)
857+
else:
858+
data = DataFrame(data, columns=self.varlist, index=index)
856859

857860
cols_ = np.where(self.dtyplist)[0]
858861
for i in cols_:

pandas/io/tests/test_stata.py

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ def read_dta(self, file):
7272
def read_csv(self, file):
7373
return read_csv(file, parse_dates=True)
7474

75+
def test_read_empty_dta(self):
76+
empty_ds = DataFrame(columns=['unit'])
77+
# GH 7369, make sure can read a 0-obs dta file
78+
with tm.ensure_clean() as path:
79+
empty_ds.to_stata(path,write_index=False)
80+
empty_ds2 = read_stata(path)
81+
tm.assert_frame_equal(empty_ds, empty_ds2)
82+
7583
def test_read_dta1(self):
7684
reader_114 = StataReader(self.dta1_114)
7785
parsed_114 = reader_114.data()

0 commit comments

Comments
 (0)