File tree 2 files changed +14
-6
lines changed
2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ Fixed regressions
83
83
- Fixed :meth: `.DataFrameGroupBy.size ` not returning a Series when ``axis=1 `` (:issue: `48738 `)
84
84
- Fixed Regression in :meth: `DataFrameGroupBy.apply ` when user defined function is called on an empty dataframe (:issue: `47985 `)
85
85
- Fixed regression in :meth: `DataFrame.apply ` when passing non-zero ``axis `` via keyword argument (:issue: `48656 `)
86
- -
86
+ - Fixed regression in Stata reading where files were needlessly buffered in memory ( :issue: ` 48922 `)
87
87
88
88
.. ---------------------------------------------------------------------------
89
89
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