Skip to content

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

Merged
merged 7 commits into from
Jul 3, 2018

Conversation

jbrockmendel
Copy link
Member

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 to Tick. Then in tslibs.period we can replace isinstance(obj, offsets.Tick) checks with isinstnace(obj, _Tick), obviating the need for the import of tseries.offsets. This moves us closer to being able to import Period 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.

@codecov
Copy link

codecov bot commented Jul 1, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@be14333). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #21694   +/-   ##
=========================================
  Coverage          ?    91.9%           
=========================================
  Files             ?      154           
  Lines             ?    49638           
  Branches          ?        0           
=========================================
  Hits              ?    45620           
  Misses            ?     4018           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.27% <100%> (?)
#single 41.9% <100%> (?)
Impacted Files Coverage Δ
pandas/tseries/offsets.py 97.15% <100%> (ø)

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 be14333...7e69e7b. Read the comment docs.

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

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

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.

tiny comment ping on green.

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,
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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.

@jreback jreback added Frequency DateOffsets Clean labels Jul 2, 2018
@jreback jreback added this to the 0.24.0 milestone Jul 2, 2018
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.

minor comments, ping on green.

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,
Copy link
Contributor

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.

@jreback
Copy link
Contributor

jreback commented Jul 2, 2018

lgtm. ping on green.

@jbrockmendel
Copy link
Member Author

ping

@jreback jreback merged commit a70e356 into pandas-dev:master Jul 3, 2018
@jreback
Copy link
Contributor

jreback commented Jul 3, 2018

thank you sir!

@jbrockmendel jbrockmendel deleted the addsub branch July 3, 2018 14:46
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants