-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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: pd.offsets.MonthEnd() delevers wrong month #49133
Closed
jtimko16
wants to merge
6
commits into
pandas-dev:main
from
jtimko16:BUG-pd.offsets.MonthEnd()-delevers-wrong-month
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
336998e
Update offsets.pyx
jtimko16 fae682d
Clear whitespaces
jtimko16 2bf9a87
[DOCS] - Added more comment and examples of n parameter
jtimko16 e8552c2
Remove trailing white spaces
jtimko16 edcbdc1
Update pandas/_libs/tslibs/offsets.pyx
jtimko16 0e98b9f
Update pandas/_libs/tslibs/offsets.pyx
jtimko16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2477,11 +2477,57 @@ cdef class MonthEnd(MonthOffset): | |
""" | ||
DateOffset of one month end. | ||
|
||
Parameters | ||
---------- | ||
n : int, default 1 | ||
n = 0 -> offset to the end of month. | ||
n = 1 -> depend on the given date: | ||
a) Given date is on an anchor point (last day of the month) -> offset to the end of the following month. | ||
b) Given date is not on an anchor point -> offset to the end of the same month. | ||
|
||
Examples | ||
-------- | ||
Offset to the end of the month: | ||
|
||
>>> ts = pd.Timestamp(2022, 1, 1) | ||
>>> ts + pd.offsets.MonthEnd() | ||
Timestamp('2022-01-31 00:00:00') | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a short sentence before the examples you've added to clarify what the reader is meant to take away from them? see https://pandas.pydata.org/docs/development/contributing_docstring.html#section-7-examples |
||
However be careful, if given date is the last day of a month, method offsets to the end of the following month: | ||
|
||
>>> ts = pd.Timestamp(2022, 1, 31) | ||
>>> ts + pd.offsets.MonthEnd() | ||
Timestamp('2022-02-28 00:00:00') | ||
|
||
With the ``n`` parameter, we can control logic of offset. | ||
|
||
See below, when ``n`` is set to 0, offset is always made to the end of the current month: | ||
|
||
>>> ts = pd.Timestamp(2022, 1, 31) | ||
>>> ts + pd.offsets.MonthEnd(n=0) | ||
Timestamp('2022-01-31 00:00:00') | ||
|
||
When ``n`` is set to 1 (default) it will be moved to the following month: | ||
|
||
>>> ts = pd.Timestamp(2022, 1, 31) | ||
>>> ts + pd.offsets.MonthEnd(n=1) | ||
Timestamp('2022-02-28 00:00:00') | ||
|
||
When ``n`` is set to 2, method offsets one additional month. And again depends whether given date is on an anchor point: | ||
|
||
>>> ts = pd.Timestamp(2022, 1, 1) | ||
>>> ts + pd.offsets.MonthEnd(n=2) | ||
Timestamp('2022-02-28 00:00:00') | ||
|
||
>>> ts = pd.Timestamp(2022, 1, 31) | ||
>>> ts + pd.offsets.MonthEnd(n=2) | ||
Timestamp('2022-03-31 00:00:00') | ||
|
||
Also we can use negative ``n`` to find end of previous months: | ||
|
||
>>> ts = pd.Timestamp(2022, 1, 31) | ||
>>> ts + pd.offsets.MonthEnd(n=-1) | ||
Timestamp('2021-12-31 00:00:00') | ||
""" | ||
_period_dtype_code = PeriodDtypeCode.M | ||
_prefix = "M" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
does this look right? can you try building this page of the docs to check please? https://pandas.pydata.org/docs/dev/development/contributing_documentation.html
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.
Ok, but I will need more time for this. I still have trouble with setting up virtual environment (spend one hour with it today and will continue tomorrow)
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.
What is the version of Python you are using? I created a virtual environment on top of Python 3.10, and trying to install packagse from requirements-dev.txt, however it always stuck at installation of boto3:
`
Is it better to use older version of Python - e.g. 3.9? Thanks
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'd suggest using mamba https://pandas.pydata.org/docs/dev/development/contributing_environment.html#option-1a-using-mamba-recommended
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.
please do ask (here or on Slack) if it's unclear / anything trips you up
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 tried to run it again, and also installed C++ Build Tools, but still receiving similar error. Please see below the full traceback:
Traceback_error.txt
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 don't know, sorry - you could ask on Slack , or try using Ubuntu via the WSL on Windows
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.
Hi, thank you. I don't want to sound like giving up. However unfortunately, this is going deeper and deeper technical, and I feel I am not able to effectively contribute. Is it OK, if I share the updated text of documentation in thread under the issue, and leave it for someone more technically capable to proceed with implementation?
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, that's fine, someone else can take this forwards, and if you feel like trying again, feel free to reach out and ask
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.
Ok, thanks. Maybe I will give it another go this weekend. Will let you know how I decide to proceed then. Thanks