From 28d1cbe6cefa4561d79c8cf6245f3448b4f5b422 Mon Sep 17 00:00:00 2001 From: louispotok Date: Wed, 27 Sep 2017 09:39:02 -0700 Subject: [PATCH] minor fixups --- doc/source/io.rst | 1 + pandas/io/json/json.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/source/io.rst b/doc/source/io.rst index 55ca43b0d03c3..4eba9687efc58 100644 --- a/doc/source/io.rst +++ b/doc/source/io.rst @@ -2064,6 +2064,7 @@ For line-delimited json files, pandas can also return an iterator which reads in df df.to_json(orient='records', lines=True) + # reader is an iterator that returns `chunksize` lines each iteration reader = pd.read_json(StringIO(jsonl), lines=True, chunksize=1) reader for chunk in reader: diff --git a/pandas/io/json/json.py b/pandas/io/json/json.py index 9f0ad24639b7c..ab74b265b6a06 100644 --- a/pandas/io/json/json.py +++ b/pandas/io/json/json.py @@ -432,7 +432,7 @@ def _get_data_from_filepath(self, filepath_or_buffer): return data - def combine_lines(self, lines): + def _combine_lines(self, lines): """Combines a list of JSON objects into one JSON object""" lines = filter(None, map(lambda x: x.strip(), lines)) return '[' + ','.join(lines) + ']' @@ -443,7 +443,7 @@ def read(self): obj = concat(self) elif self.lines: obj = self._get_object_parser( - self.combine_lines(self.data.split('\n')) + self._combine_lines(self.data.split('\n')) ) else: obj = self._get_object_parser(self.data) @@ -486,7 +486,7 @@ def close(self): def __next__(self): lines = list(islice(self.data, self.chunksize)) if lines: - lines_json = self.combine_lines(lines) + lines_json = self._combine_lines(lines) obj = self._get_object_parser(lines_json) # Make sure that the returned objects have the right index.