-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
move _add__ and __sub__ to liboffsets, implement _Tick #21694
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #21694 +/- ##
=========================================
Coverage ? 91.9%
=========================================
Files ? 154
Lines ? 49638
Branches ? 0
=========================================
Hits ? 45620
Misses ? 4018
Partials ? 0
Continue to review full report at Codecov.
|
pandas/_libs/tslibs/offsets.pyx
Outdated
@@ -491,6 +510,12 @@ class BaseOffset(_BaseOffset): | |||
return -self + other | |||
|
|||
|
|||
class _Tick(object): | |||
# dummy class to mix into tseries.Tick so that in tslibs.period we can |
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.
can u use triple quotes here
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.
tiny comment ping on green.
pandas/_libs/tslibs/offsets.pyx
Outdated
if isinstance(other, datetime): | ||
raise TypeError('Cannot subtract datetime from offset.') | ||
elif type(other) == type(self): | ||
return self.__class__(self.n - other.n, normalize=self.normalize, |
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.
can you change to use type(self)
here, I don't think we use the long form anywhere.
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.
its used below in __mul__
. change it there too while I'm at it?
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.
yeah might as well, its a bit more clean.
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.
minor comments, ping on green.
pandas/_libs/tslibs/offsets.pyx
Outdated
if isinstance(other, datetime): | ||
raise TypeError('Cannot subtract datetime from offset.') | ||
elif type(other) == type(self): | ||
return self.__class__(self.n - other.n, normalize=self.normalize, |
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.
yeah might as well, its a bit more clean.
lgtm. ping on green. |
ping |
thank you sir! |
Last one for now.
Moving
__add__
and__sub__
to liboffsets has been viable for a while now, just getting around to it.Implements a dummy
_Tick
class that gets mixed in toTick
. Then intslibs.period
we can replaceisinstance(obj, offsets.Tick)
checks withisinstnace(obj, _Tick)
, obviating the need for the import oftseries.offsets
. This moves us closer to being able to importPeriod
directly in_libs.__init__
, which has been a long-time goal (see the comment there). In conjunction with #21693 and #21690, I think that gets us the rest of the way there.