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
If you pickle a pandas DateOffset instance with months=12, and then unpickle it, you have a DateOffset(months=12, years=1) instance (effectively a 2 year date offset object.
Arguably one shouldn't create a 12 month date offset in preference to a 1 year offset, but this is still bad behaviour imho.
Expected Output
print(loaded)
<DateOffset: months=12>
Output of pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.8.3.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
>>>pd.__version__'1.1.0.dev0+1730.geac62cf26'>>>offset=pd.DateOffset(months=12)
>>>pickle.dump(offset, open("test_date_offset.p", "wb"))
>>>loaded=pickle.load(open("test_date_offset.p", "rb"))
# The two objects appears different after __str__>>>loaded<DateOffset: months=12, years=1>>>>offset<DateOffset: months=12># They are actually equivalent when put in calculations>>>pd.to_datetime('2020-01-01') +offsetTimestamp('2021-01-01 00:00:00')
>>>pd.to_datetime('2020-01-01') +loadedTimestamp('2021-01-01 00:00:00')
We can see although these two objects appears different, but their values are equivalent in computation.
However, if we explicitly set months=12, years=1, we get a different value.
>>> offset.months
12
>>> loaded.months
12
# The original object did not have `years` attribute, but the loaded one does
>>> offset.years
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'DateOffset' object has no attribute 'years'
>>> loaded.years
1
>>> d2.months
12
>>> d2.years
1
Looks like we have some problems with the internal representations of DateOffset object. It feels like there are two separate sets of representations that are not consistent. One set is used to do the computations (i.e apply the offsets on datetime like objects). Another set is used to print and to determine if 2 objects are "equal".
[ x] I have checked that this issue has not already been reported.
[ x] 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.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
If you pickle a pandas DateOffset instance with months=12, and then unpickle it, you have a DateOffset(months=12, years=1) instance (effectively a 2 year date offset object.
Arguably one shouldn't create a 12 month date offset in preference to a 1 year offset, but this is still bad behaviour imho.
Expected Output
print(loaded)
<DateOffset: months=12>
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.8.3.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.0.3
numpy : 1.18.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.0.2
setuptools : 46.4.0.post20200518
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
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: