Skip to content

Commit d4d3a7c

Browse files
Add doc-string and type info to _is_ods_stream
1 parent b14847d commit d4d3a7c

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

pandas/io/excel/_base.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import abc
22
import datetime
3-
from io import BytesIO, IOBase
3+
from io import BytesIO, BufferedIOBase, RawIOBase
44
import os
55
from textwrap import fill
6+
from typing import Union
67

78
from pandas._config import config
89

@@ -778,7 +779,22 @@ def close(self):
778779
return self.save()
779780

780781

781-
def _is_ods_stream(stream):
782+
def _is_ods_stream(stream: Union[BufferedIOBase, RawIOBase]) -> bool:
783+
"""
784+
Check if the stream is an OpenDocument Spreadsheet (.ods) file
785+
786+
It uses magic values inside the stream
787+
788+
Parameters
789+
----------
790+
stream : Union[BufferedIOBase, RawIOBase]
791+
IO stream with data which might be an ODS file
792+
793+
Returns
794+
-------
795+
is_ods : bool
796+
Boolean indication that this is indeed an ODS file or not
797+
"""
782798
stream.seek(0)
783799
is_ods = False
784800
if stream.read(4) == b"PK\003\004":
@@ -829,7 +845,7 @@ class ExcelFile:
829845
def __init__(self, path_or_buffer, engine=None):
830846
if engine is None:
831847
engine = "xlrd"
832-
if isinstance(path_or_buffer, IOBase):
848+
if isinstance(path_or_buffer, (BufferedIOBase, RawIOBase)):
833849
if _is_ods_stream(path_or_buffer):
834850
engine = "odf"
835851
else:

0 commit comments

Comments
 (0)