Skip to content

Commit acb5f03

Browse files
committed
ENH: parsers don't use tempfile
1 parent 2b6bb03 commit acb5f03

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

pandas/io/parsers.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,20 +1149,16 @@ def __init__(self, path_or_buf):
11491149
except ImportError: # pragma: no cover
11501150
raise ImportError(_openpyxl_msg)
11511151
else:
1152-
import tempfile
1153-
fd = tempfile.NamedTemporaryFile()
1154-
fd.write(path_or_buf.read())
1155-
fd.seek(0)
1152+
data = path_or_buf.read()
11561153

11571154
try:
11581155
import xlrd
1159-
self.book = xlrd.open_workbook(fd.name)
1156+
self.book = xlrd.open_workbook(file_contents=data)
11601157
self.use_xlsx = False
11611158
except Exception:
11621159
from openpyxl.reader.excel import load_workbook
1163-
self.book = load_workbook(fd.name, use_iterators=True)
1164-
1165-
self.tmpfile = fd
1160+
buf = py3compat.BytesIO(data)
1161+
self.book = load_workbook(buf, use_iterators=True)
11661162

11671163
def __repr__(self):
11681164
return object.__repr__(self)

0 commit comments

Comments
 (0)