Skip to content

Commit 1eead96

Browse files
committed
FIX: StataReader: don't close stream implicitly
1 parent aa19635 commit 1eead96

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

pandas/io/stata.py

+4-14
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,6 @@ def read(
16961696
if (self._nobs == 0) and (nrows is None):
16971697
self._can_read_value_labels = True
16981698
self._data_read = True
1699-
self.close()
17001699
return DataFrame(columns=self._varlist)
17011700

17021701
# Handle options
@@ -1733,7 +1732,6 @@ def read(
17331732
# we are reading the file incrementally
17341733
if convert_categoricals:
17351734
self._read_value_labels()
1736-
self.close()
17371735
raise StopIteration
17381736
offset = self._lines_read * dtype.itemsize
17391737
self._path_or_buf.seek(self._data_location + offset)
@@ -1766,11 +1764,7 @@ def read(
17661764
data.index = Index(rng) # set attr instead of set_index to avoid copy
17671765

17681766
if columns is not None:
1769-
try:
1770-
data = self._do_select_columns(data, columns)
1771-
except ValueError:
1772-
self.close()
1773-
raise
1767+
data = self._do_select_columns(data, columns)
17741768

17751769
# Decode strings
17761770
for col, typ in zip(data, self._typlist):
@@ -1809,13 +1803,9 @@ def any_startswith(x: str) -> bool:
18091803
cols = np.where([any_startswith(x) for x in self._fmtlist])[0]
18101804
for i in cols:
18111805
col = data.columns[i]
1812-
try:
1813-
data[col] = _stata_elapsed_date_to_datetime_vec(
1814-
data[col], self._fmtlist[i]
1815-
)
1816-
except ValueError:
1817-
self.close()
1818-
raise
1806+
data[col] = _stata_elapsed_date_to_datetime_vec(
1807+
data[col], self._fmtlist[i]
1808+
)
18191809

18201810
if convert_categoricals and self._format_version > 108:
18211811
data = self._do_convert_categoricals(

0 commit comments

Comments
 (0)