Skip to content

Commit 374f316

Browse files
committed
FIX: StataReader: don't close stream implicitly
1 parent 0c8be88 commit 374f316

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
@@ -1710,7 +1710,6 @@ def read(
17101710
if (self._nobs == 0) and (nrows is None):
17111711
self._can_read_value_labels = True
17121712
self._data_read = True
1713-
self.close()
17141713
return DataFrame(columns=self._varlist)
17151714

17161715
# Handle options
@@ -1747,7 +1746,6 @@ def read(
17471746
# we are reading the file incrementally
17481747
if convert_categoricals:
17491748
self._read_value_labels()
1750-
self.close()
17511749
raise StopIteration
17521750
offset = self._lines_read * dtype.itemsize
17531751
self._path_or_buf.seek(self._data_location + offset)
@@ -1780,11 +1778,7 @@ def read(
17801778
data.index = Index(rng) # set attr instead of set_index to avoid copy
17811779

17821780
if columns is not None:
1783-
try:
1784-
data = self._do_select_columns(data, columns)
1785-
except ValueError:
1786-
self.close()
1787-
raise
1781+
data = self._do_select_columns(data, columns)
17881782

17891783
# Decode strings
17901784
for col, typ in zip(data, self._typlist):
@@ -1823,13 +1817,9 @@ def any_startswith(x: str) -> bool:
18231817
cols = np.where([any_startswith(x) for x in self._fmtlist])[0]
18241818
for i in cols:
18251819
col = data.columns[i]
1826-
try:
1827-
data[col] = _stata_elapsed_date_to_datetime_vec(
1828-
data[col], self._fmtlist[i]
1829-
)
1830-
except ValueError:
1831-
self.close()
1832-
raise
1820+
data[col] = _stata_elapsed_date_to_datetime_vec(
1821+
data[col], self._fmtlist[i]
1822+
)
18331823

18341824
if convert_categoricals and self._format_version > 108:
18351825
data = self._do_convert_categoricals(

0 commit comments

Comments
 (0)