Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

add fix for opening zero observation dta files #7369

Merged
merged 1 commit into from Jun 13, 2014
Jump to file or symbol
Failed to load files and symbols.
+13 −1
Split
View
@@ -123,3 +123,4 @@ Bug Fixes
- Bug where a string column name assignment to a ``DataFrame`` with a
``Float64Index`` raised a ``TypeError`` during a call to ``np.isnan``
(:issue:`7366`).
+- Bug in ``StataReader.data`` where reading a 0-observation dta failed (:issue:`7369`)
View
@@ -852,7 +852,10 @@ def data(self, convert_dates=True, convert_categoricals=True, index=None):
if convert_categoricals:
self._read_value_labels()
- data = DataFrame(data, columns=self.varlist, index=index)
+ if len(data)==0:
+ data = DataFrame(columns=self.varlist, index=index)
+ else:
+ data = DataFrame(data, columns=self.varlist, index=index)
cols_ = np.where(self.dtyplist)[0]
for i in cols_:
@@ -72,6 +72,14 @@ def read_dta(self, file):
def read_csv(self, file):
return read_csv(file, parse_dates=True)
+ def test_read_empty_dta(self):
+ empty_ds = DataFrame(columns=['unit'])
@jreback

jreback Jun 6, 2014

Contributor

add the comment GH 7369 here

+ # GH 7369, make sure can read a 0-obs dta file
+ with tm.ensure_clean() as path:
+ empty_ds.to_stata(path,write_index=False)
+ empty_ds2 = read_stata(path)
+ tm.assert_frame_equal(empty_ds, empty_ds2)
+
def test_read_dta1(self):
reader_114 = StataReader(self.dta1_114)
parsed_114 = reader_114.data()