Skip to content

Commit ecdbc10

Browse files
committed
refactor nrows for json files to use a simpler regular expression
1 parent 237010e commit ecdbc10

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

pandas/io/json/_json.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -743,19 +743,16 @@ def read(self):
743743
elif self.lines:
744744
data = ensure_str(self.data)
745745
if self.nrows:
746-
compiled_pattern = re.compile("\n")
746+
compiled_pattern = re.compile(".*\n")
747747
data_iterator = compiled_pattern.finditer(data)
748-
data_surrogate = []
749-
start = 0
748+
data = []
750749
nrows_seen = 0
750+
print(data_iterator)
751751
for vals in data_iterator:
752752
if nrows_seen >= self.nrows:
753753
break
754-
begin, end = vals.span()
755-
data_surrogate.append(data[start:begin].strip())
756-
start = end
754+
data.append(vals.group(0))
757755
nrows_seen += 1
758-
data = data_surrogate
759756
else:
760757
data = data.split("\n")
761758
obj = self._get_object_parser(self._combine_lines(data))

0 commit comments

Comments
 (0)