File tree 2 files changed +15
-6
lines changed
2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -229,7 +229,8 @@ MultiIndex
229
229
I/O
230
230
^^^
231
231
- Bug in :func: `read_sas ` caused fragmentation of :class: `DataFrame ` and raised :class: `.errors.PerformanceWarning ` (:issue: `48595 `)
232
- -
232
+ - Regression in :class: `StataReader ` caused all files to needlessly be buffered in memory (:issue: `48922 `)
233
+
233
234
234
235
Period
235
236
^^^^^^
Original file line number Diff line number Diff line change @@ -1164,15 +1164,23 @@ def __init__(
1164
1164
self ._lines_read = 0
1165
1165
1166
1166
self ._native_byteorder = _set_endianness (sys .byteorder )
1167
- with get_handle (
1167
+
1168
+ handles = get_handle (
1168
1169
path_or_buf ,
1169
1170
"rb" ,
1170
1171
storage_options = storage_options ,
1171
1172
is_text = False ,
1172
1173
compression = compression ,
1173
- ) as handles :
1174
- # Copy to BytesIO, and ensure no encoding
1175
- self .path_or_buf = BytesIO (handles .handle .read ())
1174
+ )
1175
+ if hasattr (handles .handle , "seekable" ) and handles .handle .seekable ():
1176
+ # If the handle is directly seekable, use it without an extra copy.
1177
+ self .path_or_buf = handles .handle
1178
+ self ._close_file = handles .close
1179
+ else :
1180
+ # Copy to memory, and ensure no encoding.
1181
+ with handles :
1182
+ self .path_or_buf = BytesIO (handles .handle .read ())
1183
+ self ._close_file = self .path_or_buf .close
1176
1184
1177
1185
self ._read_header ()
1178
1186
self ._setup_dtype ()
@@ -1192,7 +1200,7 @@ def __exit__(
1192
1200
1193
1201
def close (self ) -> None :
1194
1202
"""close the handle if its open"""
1195
- self .path_or_buf . close ()
1203
+ self ._close_file ()
1196
1204
1197
1205
def _set_encoding (self ) -> None :
1198
1206
"""
You can’t perform that action at this time.
0 commit comments