Skip to content

Commit 5e127a4

Browse files
committed
FIX: StataReader: don't close stream implicitly
1 parent c73a429 commit 5e127a4

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
@@ -1706,7 +1706,6 @@ def read(
17061706
if (self._nobs == 0) and (nrows is None):
17071707
self._can_read_value_labels = True
17081708
self._data_read = True
1709-
self.close()
17101709
return DataFrame(columns=self._varlist)
17111710

17121711
# Handle options
@@ -1743,7 +1742,6 @@ def read(
17431742
# we are reading the file incrementally
17441743
if convert_categoricals:
17451744
self._read_value_labels()
1746-
self.close()
17471745
raise StopIteration
17481746
offset = self._lines_read * dtype.itemsize
17491747
self._path_or_buf.seek(self._data_location + offset)
@@ -1776,11 +1774,7 @@ def read(
17761774
data.index = Index(rng) # set attr instead of set_index to avoid copy
17771775

17781776
if columns is not None:
1779-
try:
1780-
data = self._do_select_columns(data, columns)
1781-
except ValueError:
1782-
self.close()
1783-
raise
1777+
data = self._do_select_columns(data, columns)
17841778

17851779
# Decode strings
17861780
for col, typ in zip(data, self._typlist):
@@ -1819,13 +1813,9 @@ def any_startswith(x: str) -> bool:
18191813
cols = np.where([any_startswith(x) for x in self._fmtlist])[0]
18201814
for i in cols:
18211815
col = data.columns[i]
1822-
try:
1823-
data[col] = _stata_elapsed_date_to_datetime_vec(
1824-
data[col], self._fmtlist[i]
1825-
)
1826-
except ValueError:
1827-
self.close()
1828-
raise
1816+
data[col] = _stata_elapsed_date_to_datetime_vec(
1817+
data[col], self._fmtlist[i]
1818+
)
18291819

18301820
if convert_categoricals and self._format_version > 108:
18311821
data = self._do_convert_categoricals(

0 commit comments

Comments
 (0)