Skip to content

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

Merged
merged 6 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Timezones
Offsets
^^^^^^^

-
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

- :class:`Tick` subclasses can no longer be created with the argument `normalize=True` (:issue:`21427`)
Copy link
Contributor

Choose a reason for hiding this comment

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

double backticks here. I would be a little more informative (say for example Minute, Second).

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do.

-
-

Expand Down
22 changes: 20 additions & 2 deletions pandas/tests/tseries/offsets/test_offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
YearEnd, Day,
QuarterEnd, BusinessMonthEnd, FY5253,
Nano, Easter, FY5253Quarter,
LastWeekOfMonth)
LastWeekOfMonth, Tick)
from pandas.core.tools.datetimes import format, ole2datetime
import pandas.tseries.offsets as offsets
from pandas.io.pickle import read_pickle
Expand Down Expand Up @@ -225,6 +225,11 @@ def test_offset_freqstr(self, offset_types):

def _check_offsetfunc_works(self, offset, funcname, dt, expected,
normalize=False):

if normalize and issubclass(offset, Tick):
# normalize=True disallowed for Tick subclasses GH#21427
return

offset_s = self._get_offset(offset, normalize=normalize)
func = getattr(offset_s, funcname)

Expand Down Expand Up @@ -413,6 +418,9 @@ def test_onOffset(self, offset_types):
assert offset_s.onOffset(dt)

# when normalize=True, onOffset checks time is 00:00:00
if issubclass(offset_types, Tick):
# normalize=True disallowed for Tick subclasses GH#21427
return
offset_n = self._get_offset(offset_types, normalize=True)
assert not offset_n.onOffset(dt)

Expand Down Expand Up @@ -440,7 +448,9 @@ def test_add(self, offset_types, tz):
assert isinstance(result, Timestamp)
assert result == expected_localize

# normalize=True
# normalize=True, disallowed for Tick subclasses GH#21427
if issubclass(offset_types, Tick):
return
offset_s = self._get_offset(offset_types, normalize=True)
expected = Timestamp(expected.date())

Expand Down Expand Up @@ -3140,6 +3150,14 @@ def test_require_integers(offset_types):
cls(n=1.5)


def test_tick_normalize_raises(tick_classes):
# check that trying to create a Tick object with normalize=True raises
# GH#21427
cls = tick_classes
with pytest.raises(ValueError):
cls(n=3, normalize=True)


def test_weeks_onoffset():
# GH#18510 Week with weekday = None, normalize = False should always
# be onOffset
Expand Down
3 changes: 3 additions & 0 deletions pandas/tseries/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,9 @@ class Tick(SingleConstructorOffset):
def __init__(self, n=1, normalize=False):
# TODO: do Tick classes with normalize=True make sense?
Copy link
Member

@gfyoung gfyoung Jun 11, 2018

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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)
Expand Down