-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
ENH: allow using '+' sign in the argument to to_offset()
#18171
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
ENH: allow using '+' sign in the argument to to_offset()
#18171
Conversation
I made the change here in frequencies.pxd, which presumably means that now frequencies can also be specified with a '+' sign. Maybe this is not desired, in which case I could include a modified version of the |
Should the whatsnew entry go in "Other API changes"? |
Also, does this need a separate issue? |
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.
This can go under "Other Enhancements" and you can use 18171 for the issue number. No need for a separate issue.
pandas/tseries/frequencies.py
Outdated
except Exception: | ||
raise ValueError(_INVALID_FREQ_ERROR.format(freq)) | ||
except Exception as e: | ||
raise ValueError(_INVALID_FREQ_ERROR.format(freq)) from e |
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 think this is valid syntax in python 2
@@ -169,6 +169,15 @@ def test_to_offset_leading_zero(self): | |||
result = frequencies.to_offset(freqstr) | |||
assert (result.n == -194) | |||
|
|||
def test_to_offset_leading_plus(self): |
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.
Could you add a couple invalid freqstrs, like '+-1d'
, '-+1d'
, '+1'
, '+d'
and ensure that they all raise.
At least I think they should all raise? d
is apparently valid, but -d
isn't.
b20de97
to
71bd8db
Compare
Codecov Report
@@ Coverage Diff @@
## master #18171 +/- ##
==========================================
- Coverage 91.42% 91.38% -0.05%
==========================================
Files 163 163
Lines 50064 50068 +4
==========================================
- Hits 45772 45755 -17
- Misses 4292 4313 +21
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #18171 +/- ##
=========================================
Coverage ? 91.38%
=========================================
Files ? 163
Lines ? 50064
Branches ? 0
=========================================
Hits ? 45751
Misses ? 4313
Partials ? 0
Continue to review full report at Codecov.
|
71bd8db
to
2d8763a
Compare
to_offset()
to_offset()
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.
small doc change. ping on green.
doc/source/whatsnew/v0.22.0.txt
Outdated
@@ -23,7 +23,7 @@ Other Enhancements | |||
^^^^^^^^^^^^^^^^^^ | |||
|
|||
- Better support for ``Dataframe.style.to_excel()`` output with the ``xlsxwriter`` engine. (:issue:`16149`) | |||
- | |||
- ``pd.tseries.frequencies.to_offset()`` now accepts '+' signs e.g. '+1h'. (:issue:`18171`) |
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.
use a :func:`pandas.tseries.frequencies.to_offset`
here
say accepts leading '+' signs
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, done
2d8763a
to
5d0b363
Compare
@@ -23,7 +23,7 @@ Other Enhancements | |||
^^^^^^^^^^^^^^^^^^ | |||
|
|||
- Better support for ``Dataframe.style.to_excel()`` output with the ``xlsxwriter`` engine. (:issue:`16149`) | |||
- | |||
- :func:`pd.tseries.frequencies.to_offset()` now accepts leading '+' signs e.g. '+1h'. (:issue:`18171`) |
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 this needs to be pandas (and not pd)
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.
The other entries in the file all say 'pd' and not 'pandas'. In previous whatsnew.txt files there seems to be a mixture but still a preponderance of 'pd'
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.
hmm, then maybe this works. ok.
thanks @frexvahi |
git diff upstream/master -u -- "*.py" | flake8 --diff