Skip to content

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

Merged
merged 3 commits into from
Nov 10, 2017

Conversation

frexvahi
Copy link
Contributor

@frexvahi frexvahi commented Nov 8, 2017

  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

@frexvahi
Copy link
Contributor Author

frexvahi commented Nov 8, 2017

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 opattern regexp in the to_offset function itself.

@frexvahi
Copy link
Contributor Author

frexvahi commented Nov 8, 2017

Should the whatsnew entry go in "Other API changes"?

@frexvahi
Copy link
Contributor Author

frexvahi commented Nov 8, 2017

Also, does this need a separate issue?

Copy link
Contributor

@TomAugspurger TomAugspurger left a 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.

except Exception:
raise ValueError(_INVALID_FREQ_ERROR.format(freq))
except Exception as e:
raise ValueError(_INVALID_FREQ_ERROR.format(freq)) from e
Copy link
Contributor

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):
Copy link
Contributor

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.

@TomAugspurger TomAugspurger added this to the 0.22.0 milestone Nov 8, 2017
@TomAugspurger TomAugspurger added Frequency DateOffsets Datetime Datetime data dtype API Design labels Nov 8, 2017
@frexvahi frexvahi force-pushed the allow-plus-sign-in-to_offset branch from b20de97 to 71bd8db Compare November 9, 2017 17:03
@codecov
Copy link

codecov bot commented Nov 9, 2017

Codecov Report

Merging #18171 into master will decrease coverage by 0.04%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Flag Coverage Δ
#multiple 89.19% <100%> (-0.03%) ⬇️
#single 40.33% <0%> (-0.09%) ⬇️
Impacted Files Coverage Δ
pandas/tseries/frequencies.py 96% <100%> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/plotting/_converter.py 63.38% <0%> (-1.82%) ⬇️
pandas/core/frame.py 97.8% <0%> (-0.1%) ⬇️
pandas/core/generic.py 95.72% <0%> (ø) ⬆️
pandas/io/formats/format.py 96.01% <0%> (ø) ⬆️
pandas/core/config_init.py 98.34% <0%> (ø) ⬆️
pandas/io/parquet.py 65.38% <0%> (ø) ⬆️
pandas/compat/__init__.py 58.1% <0%> (ø) ⬆️
pandas/core/groupby.py 92.04% <0%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 17e0b13...71bd8db. Read the comment docs.

@codecov
Copy link

codecov bot commented Nov 9, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@a6345c7). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #18171   +/-   ##
=========================================
  Coverage          ?   91.38%           
=========================================
  Files             ?      163           
  Lines             ?    50064           
  Branches          ?        0           
=========================================
  Hits              ?    45751           
  Misses            ?     4313           
  Partials          ?        0
Flag Coverage Δ
#multiple 89.19% <ø> (?)
#single 40.36% <ø> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a6345c7...5d0b363. Read the comment docs.

@frexvahi frexvahi force-pushed the allow-plus-sign-in-to_offset branch from 71bd8db to 2d8763a Compare November 9, 2017 17:05
@frexvahi frexvahi changed the title Allow using '+' sign in the argument to to_offset() ENH: allow using '+' sign in the argument to to_offset() Nov 10, 2017
Copy link
Contributor

@jreback jreback left a 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.

@@ -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`)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done

@frexvahi frexvahi force-pushed the allow-plus-sign-in-to_offset branch from 2d8763a to 5d0b363 Compare November 10, 2017 14:05
@@ -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`)
Copy link
Contributor

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)

Copy link
Contributor Author

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'

Copy link
Contributor

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.

@jreback jreback merged commit 75c1fa0 into pandas-dev:master Nov 10, 2017
@jreback
Copy link
Contributor

jreback commented Nov 10, 2017

thanks @frexvahi

@frexvahi frexvahi deleted the allow-plus-sign-in-to_offset branch November 10, 2017 14:25
No-Stream pushed a commit to No-Stream/pandas that referenced this pull request Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Datetime Datetime data dtype Frequency DateOffsets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants