-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
disallow normalize=True with Tick classes #21427
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
Changes from 4 commits
a9cc9f0
b4cbaa9
6a28813
053aa14
44a2cde
d15d137
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,33 @@ Backwards incompatible API changes | |
|
||
.. _whatsnew_0240.api.datetimelike: | ||
|
||
Tick DateOffset Normalize Restrictions | ||
-------------------------------------- | ||
|
||
Creating a ``Tick`` object (:class:``Day``, :class:``Hour``, :class:``Minute``, | ||
:class:``Second``, :class:``Milli``, :class:``Micro``, :class:``Nano``) with | ||
`normalize=True` is no longer supported. This prevents unexpected behavior | ||
where addition could fail to be monotone or associative. | ||
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. add the issue number here |
||
|
||
.. ipython:: python | ||
|
||
ts = pd.Timestamp('2018-06-11 18:01:14') | ||
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. show ts and tic here 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. Will do. Does showing the tic here work given that the line that defines it will raise in the new version? |
||
tic = pd.offsets.Hour(n=2, normalize=True) | ||
|
||
Previous Behavior: | ||
|
||
.. code-block:: ipython | ||
|
||
In [2]: ts = pd.Timestamp('2018-06-11 18:01:14') | ||
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. you don't need to repeat ts & tic here, just the calculations |
||
|
||
In [3]: tic = pd.offsets.Hour(n=2, normalize=True) | ||
|
||
In [4]: ts + tic | ||
Out [4]: Timestamp('2018-06-11 00:00:00') | ||
|
||
In [5]: ts + tic + tic + tic == ts + (tic + tic + tic) | ||
Out [5]: False | ||
|
||
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. add the Current behavior via an ipython block (obviously w/o normalize passed) 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. OK. And just the same |
||
Datetimelike API Changes | ||
^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
|
@@ -112,7 +139,7 @@ Timezones | |
Offsets | ||
^^^^^^^ | ||
|
||
- | ||
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. if you have a subsection, you don't need a note, the subsection IS the note. |
||
- Fixed a bug where :class:``Tick`` subclasses (:class:``Day``, :class:``Hour``, :class:``Minute``, :class:``Second``, :class:``Milli``, :class:``Micro``, :class:``Nano``) could be created with the argument `normalize=True`, which could lead to addition failing to be monotone or associative (:issue:`21427`,:issue:`21434`) | ||
- | ||
- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2219,6 +2219,9 @@ class Tick(SingleConstructorOffset): | |
def __init__(self, n=1, normalize=False): | ||
# TODO: do Tick classes with normalize=True make sense? | ||
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. It seems like this was a broader API design question. Depending on how things go, creating an issue to "close" with this PR might be appropriate. cc @jreback 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. @jbrockmendel : Could you remove this comment? Looks like your fix is here to say. 😄 |
||
self.n = self._validate_n(n) | ||
if normalize: | ||
raise ValueError("Tick offset with `normalize=True` are not " | ||
"allowed.") # GH#21427 | ||
self.normalize = normalize | ||
|
||
__gt__ = _tick_comp(operator.gt) | ||
|
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.
add a ref to this section (this is a new one, like: _whatsnew_0240.api.datetimelike.normalize )