@@ -94,6 +94,7 @@ def _open_input(p: PathOrIO) -> TextIO:
94
94
if isinstance (p , str ) and (p .startswith ("http://" ) or p .startswith ("https://" )):
95
95
# It's a URL
96
96
data = requests .get (p , timeout = 30 ).content
97
+ # TODO handle gzipped remote content
97
98
return io .StringIO (data .decode ("utf-8" ))
98
99
99
100
# squash a path to a string so we don't have to duplicate logic below
@@ -151,13 +152,20 @@ def _separate_metadata_and_table_from_stream(stream: TextIO):
151
152
return table_component , metadata_component
152
153
153
154
154
- def _read_pandas_and_metadata (stream : TextIO , sep : Optional [str ] = None ):
155
+ def _read_pandas_and_metadata (file_path : PathOrIO , sep : Optional [str ] = None ):
155
156
"""Read a tabular data file by wrapping func:`pd.read_csv` to handles comment lines correctly.
156
157
157
- :param stream : The file to read. If no separator is given, this file should be named.
158
+ :param file_path : The file path or stream to read
158
159
:param sep: File separator for pandas
159
160
:return: A pandas dataframe
160
161
"""
162
+ if sep is None :
163
+ sep = _infer_separator (file_path )
164
+
165
+ if isinstance (file_path , (str , Path )):
166
+ raise_for_bad_path (file_path )
167
+
168
+ stream = _open_input (file_path )
161
169
table_stream , metadata_stream = _separate_metadata_and_table_from_stream (stream )
162
170
163
171
try :
@@ -317,12 +325,8 @@ def parse_sssom_table(
317
325
"""
318
326
if kwargs :
319
327
logging .warning ("unhandled keyword arguments passed: %s" , kwargs )
320
- if isinstance (file_path , Path ) or isinstance (file_path , str ):
321
- raise_for_bad_path (file_path )
322
- stream = _open_input (file_path )
323
- if sep is None :
324
- sep = _infer_separator (file_path )
325
- df , sssom_metadata = _read_pandas_and_metadata (stream , sep )
328
+
329
+ df , sssom_metadata = _read_pandas_and_metadata (file_path , sep )
326
330
if meta is None :
327
331
meta = {}
328
332
0 commit comments