-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fix invalid relativedelta_kwds #19398
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
Conversation
add a whatsnew entry. let's add/update a doc-string for DateOffset. |
Saying what? This shouldn't change anything user-facing.
Sure. Just in |
Codecov Report
@@ Coverage Diff @@
## master #19398 +/- ##
=======================================
Coverage 91.6% 91.6%
=======================================
Files 150 150
Lines 48750 48750
=======================================
Hits 44657 44657
Misses 4093 4093
Continue to review full report at Codecov.
|
Just added relativedelta params to the DateOffset docstring... not wild about encouraging users to use these. |
@@ -182,6 +182,29 @@ def __add__(date): | |||
date + BDay(0) == BDay.rollforward(date) | |||
|
|||
Since 0 is a bit weird, we suggest avoiding its use. | |||
|
|||
Parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, can you separate this into 2 subsections and make clear the different behavior (via an example)
In [1]: t = pd.Timestamp('20170101 09:10:11')
# operate with the value
In [3]: t + DateOffset(years=2018)
Out[3]: datetime.datetime(4035, 1, 1, 9, 10, 11)
In [5]: t + DateOffset(seconds=1)
Out[5]: Timestamp('2017-01-01 09:10:12')
# set the value
In [6]: t + DateOffset(second=1)
Out[6]: Timestamp('2017-01-01 09:10:01')
In [8]: t + DateOffset(month=1)
Out[8]: Timestamp('2017-01-01 09:10:11')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is an issue to revisit this (IOW we should have 2 different offsets for this different behaviors)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. The docstring is already pretty big and likely to get much bigger. Is there somewhere else part of it should go?
there is an issue to revisit this (IOW we should have 2 different offsets for this different behaviors)
Yah, IIRC there was a suggestion to have __new__
dispatch some special cases to Tick
, MonthOffset
, etc. I'm planning to take a swing at that after the immutabilization since __new__
and cython are tricky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't make it long, make it wide instead (its a bit non-standard ok)
n : int, default 1
normalize : bool, default False
Parameters that ADD to the offset
----------------------------------
years, months, ....
Parameters that REPLACE the offset value
-----------
year, month
@@ -243,10 +243,10 @@ def _validate_business_time(t_input): | |||
|
|||
relativedelta_kwds = set([ | |||
'years', 'months', 'weeks', 'days', | |||
'year', 'month', 'week', 'day', 'weekday', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically this is an api change, IOW week & milliseconds cannot be passed anymore (maybe add this PR number somwhere)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shoot you're right.
@@ -182,6 +182,29 @@ def __add__(date): | |||
date + BDay(0) == BDay.rollforward(date) | |||
|
|||
Since 0 is a bit weird, we suggest avoiding its use. | |||
|
|||
Parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't make it long, make it wide instead (its a bit non-standard ok)
n : int, default 1
normalize : bool, default False
Parameters that ADD to the offset
----------------------------------
years, months, ....
Parameters that REPLACE the offset value
-----------
year, month
pandas/tseries/offsets.py
Outdated
n : int (default 1) | ||
normalize : bool (default False) | ||
|
||
Parameters that ADD to the offset (like Timedelta) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomAugspurger @jorisvandenbossche
will this work formatting wise? (prob needs even more in this doc-string, but this is a good start)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will not work formatting wise for sphinx / online docs, I think (should try out to be sure, but I think numpydoc does not accept custom sections)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative would be to do like (but then with all options listed where I put ...
):
Parameters
----------
...
years, months, weeks, ... nanoseconds : int, optional
Parameters that ADD to the offset (like Timedelta)
year, month, week, ..., nanosecond : int, optional
Parameters that REPLACE the offset value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that recent numpydocs raise if there are extra sections, so this won't work.
There is another subtle problem here in that if relativedelta kwargs are passed and nano kwargs are passed, the nano is silently ignored (except in @jorisvandenbossche 's formatting idea makes sense. |
Temporarily closing to clear out the queue |
@datapythonista thoughts on how to handle the doc string here? |
What do you think about something like this?
|
Implemented @datapythonista's suggestion, reopening. |
thanks @jbrockmendel and @datapythonista I think the doc-string is pretty good. maybe add some more examples? |
git diff upstream/master -u -- "*.py" | flake8 --diff