Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
# write a csv file to read with read_csv()
dummy_csv = """col_a
10
20
30
40"""
with open("dummy.csv", "w") as file:
file.write(dummy_csv)
# fetch a TextFileReader to iterate through the file chunk by chunk
text_file_reader = pd.read_csv("dummy.csv",
skiprows=lambda row: False,
engine='python',
chunksize=3)
with text_file_reader as reader:
iterator = iter(reader)
next(iterator) # TypeError: 'function' object is not iterable
Issue Description
A TypeError is raised when iterating through a TextFileReader that was returned by read_csv() using a callable skiprows argument and the python parsing engine.
Making any one of the following changes to the read_csv() arguments causes this code example to successfully complete without raising an error:
- Setting skiprows=None
- Setting skiprows=[]
- Setting skiprows=[1]
- Setting engine='c'
Expected Behavior
This code example should complete without printing any output or raising any error.
Installed Versions
pandas : 2.1.1
numpy : 1.26.0
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.3
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader : None
bs4 : None
bottleneck : 1.3.5
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : 2.8.7
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
None