You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
importpandasaspd# write a csv file to read with read_csv()dummy_csv="""col_a10203040"""withopen("dummy.csv", "w") asfile:
file.write(dummy_csv)
# fetch a TextFileReader to iterate through the file chunk by chunktext_file_reader=pd.read_csv("dummy.csv",
skiprows=lambdarow: False,
engine='python',
chunksize=3)
withtext_file_readerasreader:
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
INSTALLED VERSIONS
------------------
commit : e86ed37
python : 3.11.5.final.0
python-bits : 64
OS : Linux
OS-release : 6.2.0-35-generic
Version : #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Oct 6 10:23:26 UTC 2
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
… specified (#55677, #56323) (#56250)
* Fix -GH 55677:
Added support for the python parser to handle using skiprows and chunk_size options at the same time to ensure API contract is met.
Added a regression test to ensure this bug can be quickly caught in the future if it reappears.
* Fix -GH 55677:
Added support for the python parser to handle using skiprows and chunk_size options at the same time to ensure API contract is met.
Added a regression test to ensure this bug can be quickly caught in the future if it reappears.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Fix -GH 55677:
Added support for the python parser to handle using skiprows and chunk_size options at the same time to ensure API contract is met.
Added a regression test to ensure this bug can be quickly caught in the future if it reappears.
* Fix -GH 55677:
Made changes consistment with mypy checking
* Fix -GH 55677:
Made changes consistment with mypy checking and pre-commit
* Fix -GH 55677 & 56323:
This commit:
-Fixes GH 56323 by replacing the python engine chunksize logic
-Fixes formatting on the added test_skiprows test case
-Fixes incorrect test in read_fwf that expected an output chunk of size 3 when chunksize=2 was specified.
* Trigger CI
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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
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:
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
The text was updated successfully, but these errors were encountered: