Skip to content

Commit bf2b281

Browse files
committed
FIX: StataReader: don't close stream implicitly
1 parent 2cbc133 commit bf2b281

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
@@ -1699,7 +1699,6 @@ def read(
16991699
if (self._nobs == 0) and (nrows is None):
17001700
self._can_read_value_labels = True
17011701
self._data_read = True
1702-
self.close()
17031702
return DataFrame(columns=self._varlist)
17041703

17051704
# Handle options
@@ -1736,7 +1735,6 @@ def read(
17361735
# we are reading the file incrementally
17371736
if convert_categoricals:
17381737
self._read_value_labels()
1739-
self.close()
17401738
raise StopIteration
17411739
offset = self._lines_read * dtype.itemsize
17421740
self._path_or_buf.seek(self._data_location + offset)
@@ -1769,11 +1767,7 @@ def read(
17691767
data.index = Index(rng) # set attr instead of set_index to avoid copy
17701768

17711769
if columns is not None:
1772-
try:
1773-
data = self._do_select_columns(data, columns)
1774-
except ValueError:
1775-
self.close()
1776-
raise
1770+
data = self._do_select_columns(data, columns)
17771771

17781772
# Decode strings
17791773
for col, typ in zip(data, self._typlist):
@@ -1812,13 +1806,9 @@ def any_startswith(x: str) -> bool:
18121806
cols = np.where([any_startswith(x) for x in self._fmtlist])[0]
18131807
for i in cols:
18141808
col = data.columns[i]
1815-
try:
1816-
data[col] = _stata_elapsed_date_to_datetime_vec(
1817-
data[col], self._fmtlist[i]
1818-
)
1819-
except ValueError:
1820-
self.close()
1821-
raise
1809+
data[col] = _stata_elapsed_date_to_datetime_vec(
1810+
data[col], self._fmtlist[i]
1811+
)
18221812

18231813
if convert_categoricals and self._format_version > 108:
18241814
data = self._do_convert_categoricals(

0 commit comments

Comments
 (0)