File tree 1 file changed +19
-3
lines changed
1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change 1
1
import abc
2
2
import datetime
3
- from io import BytesIO , IOBase
3
+ from io import BytesIO , BufferedIOBase , RawIOBase
4
4
import os
5
5
from textwrap import fill
6
+ from typing import Union
6
7
7
8
from pandas ._config import config
8
9
@@ -778,7 +779,22 @@ def close(self):
778
779
return self .save ()
779
780
780
781
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
+ """
782
798
stream .seek (0 )
783
799
is_ods = False
784
800
if stream .read (4 ) == b"PK\003 \004 " :
@@ -829,7 +845,7 @@ class ExcelFile:
829
845
def __init__ (self , path_or_buffer , engine = None ):
830
846
if engine is None :
831
847
engine = "xlrd"
832
- if isinstance (path_or_buffer , IOBase ):
848
+ if isinstance (path_or_buffer , ( BufferedIOBase , RawIOBase ) ):
833
849
if _is_ods_stream (path_or_buffer ):
834
850
engine = "odf"
835
851
else :
You can’t perform that action at this time.
0 commit comments