-
-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG:to_pickle() raises TypeError when compressing large dataframe #39002
Comments
this is failing in lzma.py which is part of python itself search for an issue there. |
Can confirm this bug here with pandas 1.2.0, but works with 1.1.5. |
I confirm having the same issue (Python 3.8.5), after upgrading to pandas 1.2.0. |
Hello, |
Same here! Exact same error for all the possible compression algorithms (tried with gz, bz2, xz, zip). Although gz doesn't throw an error but just lets the kernel crash. |
I think that I could imagine that other non-zip compression algorithms also do not like if edit: it just fails for big dataframes from bz2 import BZ2File
from gzip import GzipFile
from lzma import LZMAFile
import pickle
from zipfile import ZipFile
import pandas as pd
small_object = True
big_object = b'a' * 1000000000
small_dataframe = pd.DataFrame(range(100))
big_dataframe = pd.DataFrame(range(100000))
for obj in (small_object, big_object, small_dataframe, big_dataframe):
for module in (GzipFile, BZ2File, LZMAFile):
print(module)
with module('test.foo', mode="w") as compressed:
pickle.dump(obj, compressed, protocol=5) # fails
# compressed.write(pickle.dumps(obj, protocol=5)) # does not fail |
@TNieuwdorp you said gzip isn't working for you as well. It works for me locally and also on pandas's CI. |
Hmm, for me locally it resulted in a kernel freeze and resulting timeout/crash. Maybe this time it's a 'It doesn't run on my system' case? On 24 Jan 2021 22:02, Torsten Wörtwein <notifications@github.com> wrote:
@TNieuwdorp you said gzip isn't working for you as well. It works for me locally and also on pandas's CI.
—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or unsubscribe.
|
Confirms same bug with pandas 1.2.1 using bz2 compression |
try 1.2.2 which patches |
Confirms the same bug with pandas 1.2.3 with
|
@bluehope pls make a new issue if you are using 1.2.3 as this was patched |
Sorry, It was the problem of 'pickle', not the pandas. |
It's Python's bug, fixed in Python 3.9.6/3.10 beta 4 |
An alternative approach that would allow pickle protocol 5 in these cases (where the bug fixes are not available), would be to wrap the from bz2 import BZ2File as _BZ2File
try:
from pickle import PickleBuffer
except ImportError:
# On Python 3.7 or earlier
PickleBuffer = None
class BZ2File(_BZ2File):
def write(self, b):
if PickleBuffer is not None and isinstance(b, PickleBuffer):
try:
b = b.raw() # coerce to 1-D `uint8` C-contiguous `memoryview` zero-copy
except BufferError:
b = bytes(b) # perform in-memory copy if buffer is not contiguous
return super(BZ2File, self).write(b) Then use these wrapped versions with It seems like there are already some other IO classes being added here. Maybe that would be a natural place for this logic? Edit: Filed this suggestion as issue ( #46747 ). |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample
Problem description
the above code raises
TypeError
Note that in order to reproduce the bug, it have to:
Expected Output
the pickle should save ok
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 3e89b4c
python : 3.9.0.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : zh_CN.UTF-8
LOCALE : zh_CN.UTF-8
pandas : 1.2.0
numpy : 1.19.4
pytz : 2020.5
dateutil : 2.8.1
pip : 20.0.2
setuptools : 45.2.0
Cython : 0.29.21
pytest : 6.2.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: 0.9.0
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.5.4
sqlalchemy : None
tables : None
tabulate : 0.8.7
xarray : None
xlrd : 2.0.1
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: