Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor fixups
Browse files Browse the repository at this point in the history
louispotok committed Sep 28, 2017
1 parent 5612934 commit 28d1cbe
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/source/io.rst
Original file line number Diff line number Diff line change
@@ -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:
6 changes: 3 additions & 3 deletions pandas/io/json/json.py
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 28d1cbe

Please sign in to comment.