-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
REGR: DateOffset attributes update fails with no errors. #36940
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
Comments
This assignment was raising an error in 1.0.5 [ins] In [1]: import pandas as pd
[ins] In [2]: offset = pd.DateOffset(years=1)
[ins] In [3]: offset.years = 5
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-26637ee8202a> in <module>
----> 1 offset.years = 5
pandas/_libs/tslibs/offsets.pyx in pandas._libs.tslibs.offsets._BaseOffset.__setattr__()
AttributeError: DateOffset objects are immutable.
[ins] In [4]: pd.__version__
Out[4]: '1.0.5' and looks like this exception was removed in #34167. @jbrockmendel should this still be raising? |
Would you like me to also add a PR for an "update" method which takes a dictionary of fields to be replaced and returns a new updated DateOffset? |
Thanks for the suggestion, but I don't we'd need to add such a method to pandas since that's really the function of the constructor. |
Well, it would just be a factory method that calls the constructor without the user needing to know about the low level details of DateOffset, as I had to. It occurred to me I may have explained myself poorly:
|
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
I need to dynamically change some of the DateOffset attributes and just setting them seems like the most intuitive thing to do.
And it seems to work: no error is raised and the attribute value is updated.
When actually using it, though, the original value is used.
Expected Output
This is obviously due to the way the DateOffset is implemented, as a wrapper for cpython timedelta and dateutils relativedelta.
The ideal outcome for this would be having the object update itself, but I can understand why the class is "static".
The way it is, it may be better to inhibit attribute assignation instead of failing silently.
Event better would be having some method to generate a new DateOffset with just a couple of fields changed.
Depending on the change I may even be able to make the PR myself, once the desired behavior is clarified. :D
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 2a7d332
python : 3.7.7.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-47-generic
Version : #51~18.04.1-Ubuntu SMP Sat Sep 5 14:35:50 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.2
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.2.0.post20200714
Cython : None
pytest : 6.1.1
hypothesis : None
sphinx : 3.1.2
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: