-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
ENH: simple patch for read_json compression #16750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
from pandas import compat, isnull | ||
from pandas import Series, DataFrame, to_datetime, MultiIndex | ||
from pandas.io.common import (get_filepath_or_buffer, _get_handle, | ||
_stringify_path) | ||
_stringify_path, _infer_compression) | ||
from pandas.core.common import AbstractMethodError | ||
from pandas.io.formats.printing import pprint_thing | ||
from .normalize import _convert_to_line_delimits | ||
|
@@ -174,7 +174,7 @@ def write(self): | |
def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True, | ||
convert_axes=True, convert_dates=True, keep_default_dates=True, | ||
numpy=False, precise_float=False, date_unit=None, encoding=None, | ||
lines=False): | ||
lines=False, compression='infer'): | ||
""" | ||
Convert a JSON string to pandas object | ||
|
||
|
@@ -258,6 +258,13 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True, | |
|
||
.. versionadded:: 0.19.0 | ||
|
||
compression : {'infer', 'gzip', 'bz2', 'zip', 'xz', None}, default 'infer' | ||
For on-the-fly decompression of on-disk data. If 'infer', then use gzip, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs version added. also needs to be indendted as this won't render I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see |
||
bz2, zip or xz if filepath_or_buffer is a string ending in '.gz', '.bz2', | ||
'.zip', or 'xz', respectively, and no decompression otherwise. If using | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing a . Before xz |
||
'zip', the ZIP file must contain only one data file to be read in. | ||
Set to None for no decompression. | ||
|
||
encoding : str, default is 'utf-8' | ||
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, | |
"data": [{"index": "row 1", "col 1": "a", "col 2": "b"}, | ||
{"index": "row 2", "col 1": "c", "col 2": "d"}]}' | ||
""" | ||
compression = _infer_compression(path_or_buf, compression) | ||
filepath_or_buffer, _, compression = get_filepath_or_buffer( | ||
path_or_buf, encoding=encoding, compression=compression) | ||
|
||
filepath_or_buffer, _, _ = get_filepath_or_buffer(path_or_buf, | ||
encoding=encoding) | ||
if isinstance(filepath_or_buffer, compat.string_types): | ||
try: | ||
exists = os.path.exists(filepath_or_buffer) | ||
|
@@ -333,7 +341,8 @@ def read_json(path_or_buf=None, orient=None, typ='frame', dtype=True, | |
|
||
if exists: | ||
fh, handles = _get_handle(filepath_or_buffer, 'r', | ||
encoding=encoding) | ||
encoding=encoding, | ||
compression=compression) | ||
json = fh.read() | ||
fh.close() | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a new doc section in io.json (again see how the io.pickle compression section is done).