Skip to content

Commit 3f8f7c6

Browse files
committed
BUG: fix skiprows callable infinite loop
1 parent 04f5721 commit 3f8f7c6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

pandas/io/parsers/python_parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,8 @@ def _is_line_empty(self, line: list[Scalar]) -> bool:
667667
def _next_line(self) -> list[Scalar]:
668668
if isinstance(self.data, list):
669669
while self.skipfunc(self.pos):
670+
if self.pos >= len(self.data):
671+
break
670672
self.pos += 1
671673

672674
while True:

pandas/tests/io/excel/test_readers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,22 @@ def test_read_excel_skiprows(self, request, read_ext):
11481148
)
11491149
tm.assert_frame_equal(actual, expected)
11501150

1151+
actual = pd.read_excel(
1152+
"testskiprows" + read_ext,
1153+
sheet_name="skiprows_list",
1154+
skiprows=lambda x: x not in [1, 3, 5],
1155+
)
1156+
expected = DataFrame(
1157+
[
1158+
[1, 2.5, pd.Timestamp("2015-01-01"), True],
1159+
# [2, 3.5, pd.Timestamp("2015-01-02"), False],
1160+
[3, 4.5, pd.Timestamp("2015-01-03"), False],
1161+
# [4, 5.5, pd.Timestamp("2015-01-04"), True],
1162+
],
1163+
columns=["a", "b", "c", "d"],
1164+
)
1165+
tm.assert_frame_equal(actual, expected)
1166+
11511167
actual = pd.read_excel(
11521168
"testskiprows" + read_ext,
11531169
sheet_name="skiprows_list",

0 commit comments

Comments
 (0)