3
3
from io import StringIO
4
4
from itertools import islice
5
5
import os
6
- from typing import Any , Callable , Iterator , Optional , Type
6
+ import re
7
+ from typing import Any , Callable , Optional , Type
7
8
8
9
import numpy as np
9
10
@@ -733,15 +734,6 @@ def _combine_lines(self, lines) -> str:
733
734
lines = filter (None , map (lambda x : x .strip (), lines ))
734
735
return "[" + "," .join (lines ) + "]"
735
736
736
- def _jsonstring_to_list_generaor (self , data : str ) -> Iterator [str ]:
737
- prev_index = - 1
738
- while True :
739
- next_index = data .find ("\n " , prev_index + 1 )
740
- if next_index < 0 :
741
- break
742
- yield data [prev_index + 1 : next_index ]
743
- prev_index = next_index
744
-
745
737
def read (self ):
746
738
"""
747
739
Read the whole JSON input into a pandas object.
@@ -751,7 +743,9 @@ def read(self):
751
743
elif self .lines :
752
744
data = ensure_str (self .data )
753
745
if self .nrows :
754
- data = list (islice (self ._jsonstring_to_list_generaor (data ), self .nrows ))
746
+ compiled_pattern = re .compile ("\n " )
747
+ data_iterator = compiled_pattern .finditer ("data" )
748
+ data = list (islice (data_iterator , self .nrows ))
755
749
else :
756
750
data = data .split ("\n " )
757
751
obj = self ._get_object_parser (self ._combine_lines (data ))
0 commit comments