Skip to content

Commit a0a55c9

Browse files
committed
fixed errors with nrows iterators
1 parent b355f9c commit a0a55c9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pandas/io/json/_json.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,22 @@ def read(self):
742742
obj = concat(self)
743743
elif self.lines:
744744
data = ensure_str(self.data)
745+
print(data)
745746
if self.nrows:
746747
compiled_pattern = re.compile("\n")
747-
data_iterator = compiled_pattern.finditer("data")
748-
data = list(islice(data_iterator, self.nrows))
748+
data_iterator = compiled_pattern.finditer(data)
749+
data_surrogate = []
750+
start = 0
751+
nrows_seen = 0
752+
for vals in data_iterator:
753+
if nrows_seen >= self.nrows:
754+
break
755+
begin, end = vals.span()
756+
data_surrogate.append(data[start:begin].strip())
757+
start = end
758+
nrows_seen += 1
759+
data = data_surrogate
760+
print(data)
749761
else:
750762
data = data.split("\n")
751763
obj = self._get_object_parser(self._combine_lines(data))

0 commit comments

Comments
 (0)