File tree 1 file changed +10
-4
lines changed
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -817,8 +817,16 @@ def _parse_sheet(
817
817
dtype_backend : DtypeBackend | lib .NoDefault = lib .no_default ,
818
818
** kwds ,
819
819
):
820
- try :
821
820
821
+ if callable (skiprows ):
822
+ # In order to avoid calling skiprows multiple times on
823
+ # every row, we just do it here and keep the resulting
824
+ # list for passing it down to the parser.
825
+ skiprows = [ix for ix in range (len (data )) if skiprows (ix )]
826
+ if len (skiprows ) == 0 :
827
+ skiprows = None
828
+
829
+ try :
822
830
# header indexes reference rows after removing skiprows, so we
823
831
# create an index map from the without-skiprows to the
824
832
# original indexes.
@@ -828,9 +836,7 @@ def _parse_sheet(
828
836
ixmap = list (range (skiprows , len (data )))
829
837
elif is_list_like (skiprows ):
830
838
skiprows_set = set (cast (Sequence [int ], skiprows ))
831
- ixmap = [ix for ix , _ in enumerate (data ) if ix not in skiprows_set ]
832
- elif callable (skiprows ):
833
- ixmap = [ix for ix , _ in enumerate (data ) if not skiprows (ix )]
839
+ ixmap = [ix for ix in range (len (data )) if ix not in skiprows_set ]
834
840
else :
835
841
raise ValueError (
836
842
"skiprows must be an integer or a list of integers"
You can’t perform that action at this time.
0 commit comments