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# enough data to cause chunking into multiple filesn_data=1300df=pd.DataFrame(
{'name': ["Raphael"] *n_data,
'mask': ["red"] *n_data,
'weapon': ["sai"] *n_data,
}
)
df.to_csv('in.csv', index=False)
compression_opts=dict(method='zip')
forchunkinpd.read_csv(filepath_or_buffer='in.csv', chunksize=1000):
chunk.to_csv('out.csv.gz', mode='a', index=False, compression=compression_opts)
Issue Description
If read data by chunk from any source (tested with csv, sql) and then export them with zip compression and mode 'a' (append data) the data is not appended, but new files added to the zip file with the same name.
Thus if you read 10 chunks and export them to zip, you'll have 10 files in a zip file instead of 1.
The problem relates to zip files only. The 'gz' and without compression modes are ok
Expected Behavior
same behaviour as without compression - 1 file in a zip archive
manicko
changed the title
BUG: to_csv problems with zip compression if write by chunk
BUG: to_csv with mode 'a' and zip compression if write by chunk creates multiple files insead of appending content
Jan 8, 2024
We had similar issues in the past (seems for tar and zip) where pandas internally called write multiple times (which causes issues for zip files: https://bugs.python.org/issue2824). In your case, to_csv is called multiple times by the user, so I think we cannot find a workaround for that. It would be good to show a warning when using "a" in mode and compression in ("zip", "tar")!
twoertwein
added
IO Data
IO issues that don't fit into a more specific label
Warnings
Warnings that appear or should be added to pandas
and removed
Needs Triage
Issue that has not been reviewed by a pandas team member
labels
Jan 8, 2024
Its a pitty that zip has such limitations that it is not possible to modify file in archive. Thus it would be great if there will be notice that mod "a" is not compatible with ("zip", "tar")
The workaround is simple actually - archive with gzip and repack to zip but this could be handled by user, not pandas.
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
If read data by chunk from any source (tested with csv, sql) and then export them with zip compression and mode 'a' (append data) the data is not appended, but new files added to the zip file with the same name.
Thus if you read 10 chunks and export them to zip, you'll have 10 files in a zip file instead of 1.
The problem relates to zip files only. The 'gz' and without compression modes are ok
Expected Behavior
same behaviour as without compression - 1 file in a zip archive
Installed Versions
INSTALLED VERSIONS
commit : a671b5a
python : 3.10.8.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.17763
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
pandas : 2.1.4
numpy : 1.26.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 69.0.3
pip : 23.3.2
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 : None
dataframe-api-compat: None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
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.4
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: