8
8
from pandas import compat , isnull
9
9
from pandas import Series , DataFrame , to_datetime , MultiIndex
10
10
from pandas .io .common import (get_filepath_or_buffer , _get_handle ,
11
- _stringify_path )
11
+ _stringify_path , _infer_compression )
12
12
from pandas .core .common import AbstractMethodError
13
13
from pandas .io .formats .printing import pprint_thing
14
14
from .normalize import _convert_to_line_delimits
@@ -171,10 +171,10 @@ def write(self):
171
171
return serialized
172
172
173
173
174
- def read_json (path_or_buf = None , orient = None , typ = 'frame' , dtype = True ,
174
+ def read_json (filepath_or_buffer = None , orient = None , typ = 'frame' , dtype = True ,
175
175
convert_axes = True , convert_dates = True , keep_default_dates = True ,
176
176
numpy = False , precise_float = False , date_unit = None , encoding = None ,
177
- lines = False ):
177
+ lines = False , compression = 'infer' ):
178
178
"""
179
179
Convert a JSON string to pandas object
180
180
@@ -257,6 +257,13 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True,
257
257
Read the file as a json object per line.
258
258
259
259
.. versionadded:: 0.19.0
260
+
261
+ compression : {'infer', 'gzip', 'bz2', 'zip', 'xz', None}, default 'infer'
262
+ For on-the-fly decompression of on-disk data. If 'infer', then use gzip,
263
+ bz2, zip or xz if filepath_or_buffer is a string ending in '.gz', '.bz2',
264
+ '.zip', or 'xz', respectively, and no decompression otherwise. If using
265
+ 'zip', the ZIP file must contain only one data file to be read in.
266
+ Set to None for no decompression.
260
267
261
268
encoding : str, default is 'utf-8'
262
269
The encoding to use to decode py3 bytes.
@@ -319,9 +326,10 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True,
319
326
"data": [{"index": "row 1", "col 1": "a", "col 2": "b"},
320
327
{"index": "row 2", "col 1": "c", "col 2": "d"}]}'
321
328
"""
322
-
323
- filepath_or_buffer , _ , _ = get_filepath_or_buffer (path_or_buf ,
324
- encoding = encoding )
329
+ compression = _infer_compression (filepath_or_buffer , compression )
330
+ filepath_or_buffer , _ , compression = get_filepath_or_buffer (
331
+ filepath_or_buffer , encoding = encoding , compression = compression )
332
+
325
333
if isinstance (filepath_or_buffer , compat .string_types ):
326
334
try :
327
335
exists = os .path .exists (filepath_or_buffer )
@@ -333,7 +341,7 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True,
333
341
334
342
if exists :
335
343
fh , handles = _get_handle (filepath_or_buffer , 'r' ,
336
- encoding = encoding )
344
+ encoding = encoding , compression = compression )
337
345
json = fh .read ()
338
346
fh .close ()
339
347
else :
0 commit comments