-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: MonthBegin suggestion to get start of current month not quite right? #52106
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
Same story in #52105 I'll take a look this week about whether |
Right, the docs for DateOffset say
So, we probably shouldn't recommend it in the docs. How about we change the docs to say
and have an example like In [26]: pd.offsets.MonthBegin().rollback(pd.Timestamp('2023-03-21'))
Out[26]: Timestamp('2023-03-01 00:00:00') as well as an example like In [37]: pd.to_datetime(["2017-09-18", "2018-01-01"]).to_period('M').to_timestamp()
Out[37]: DatetimeIndex(['2017-09-01', '2018-01-01'], dtype='datetime64[ns]', freq=None) to show how to get back to the beginning of the month if one has an array? |
Hi, can I take up as my first issue to update the docs. Thankyou |
go ahead, thanks! |
take |
Hi, @MarcoGorelli quick question, I have been reading the pandas contributor docs but I am unable to find a guideline to name my local (forked) branch to add this change, could you please help me with that. Thanks |
hey - it doesn't really matter what you name your branch, up to you |
Hi @MarcoGorelli , I updated the """
DateOffset of one month at beginning.
MonthBegin goes to the next date which is a start of the month.
See Also
--------
:class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment.
Examples
--------
>>> ts = pd.Timestamp(2022, 11, 30)
>>> ts + pd.offsets.MonthBegin()
Timestamp('2022-12-01 00:00:00')
>>> ts = pd.Timestamp(2022, 12, 1)
>>> ts + pd.offsets.MonthBegin()
Timestamp('2023-01-01 00:00:00')
If you want to get the start of the current month:
>>> ts = pd.Timestamp(2022, 12, 1)
>>> pd.offsets.MonthBegin().rollback(ts)
Timestamp('2022-12-01 00:00:00')
"""
_prefix = "MS"
_day_opt = "start" and """
DateOffset of one month end.
MonthEnd goes to the next date which is an end of the month.
See Also
--------
:class:`~pandas.tseries.offsets.DateOffset` : Standard kind of date increment.
Examples
--------
>>> ts = pd.Timestamp(2022, 1, 30)
>>> ts + pd.offsets.MonthEnd()
Timestamp('2022-01-31 00:00:00')
>>> ts = pd.Timestamp(2022, 1, 31)
>>> ts + pd.offsets.MonthEnd()
Timestamp('2022-02-28 00:00:00')
If you want to get the end of the current month pass the parameter n equals 0:
>>> ts = pd.Timestamp(2022, 1, 31)
>>> pd.offsets.MonthEnd().rollforward(ts)
Timestamp('2022-01-31 00:00:00')
"""
_period_dtype_code = PeriodDtypeCode.M
_prefix = "M"
_day_opt = "end" So, is this okay and are there any more docstrings I need to update. On a side note out of curiosity what is
at the end of docstring? |
This needs updating, but the rest looks good! Those attributes are used internally in some other places (but there is an open PR to change |
so, are they like aliases for some sorts? could you please direct me to the concept being used here internally. On the other note, I have updated >>> pd.Timestamp('2023-03-21') + pd.offsets.BMonthEnd(n=0)
>>> Timestamp('2023-03-31 00:00:00') # okay
>>> pd.Timestamp('2023-03-21') + pd.offsets.BMonthBegin(n=0)
>>> Timestamp('2023-04-03 00:00:00') # not okay sould I update these docs also? |
yes please! as well as any others which you find it would be good to get this in in time for the 2.0 release, so please do open a pull request even if it's not 100% finished, I can finish it up if necessary |
Pandas version checks
main
hereLocation of the documentation
https://pandas.pydata.org/docs/dev/reference/api/pandas.tseries.offsets.MonthBegin.html?highlight=monthbegin#pandas.tseries.offsets.MonthBegin
Documentation problem
The docs for MonthEnd say
This is correct:
But for `MonthBegin, it says
I think this is not quite right:
Suggested fix for documentation
I would have expected
- pd.offsets.MonthBegin(n=0)
to go to the beginning of the current month, but it doesn't:I'm not sure if this is a bug, I've not looked closely enough.
I think I'd suggest:
+ pd.offsets.MonthBegin() - pd.offsets.MonthBegin()
to get the start of the current monthcc @natmokval in case you wanted to make a PR (no blame of course! I should have noticed this when reviewing)
The text was updated successfully, but these errors were encountered: