Skip to content

move shift_months to liboffsets, unify implementations of Q/M/Y offsets, #18375

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 4 commits into from
Nov 20, 2017

Conversation

jbrockmendel
Copy link
Member

This moves tslib.shift_months to liboffsets.

After several algebra-simplifing PRs, here's the payoff. Nearly all of the logic in M/Q/Y offset subclasses is now identical, so can be moved into the parent classes.

BusinessMonthEnd gains an onOffset method (instead of inheriting from DateOffset)

The Year and Day algebra is simple enough that the diff should be obvious. The QuarterFoo.apply methods are require a few steps of simplification before they become identical. I decided just to push the whole thing rather than drag it out.

@@ -19,6 +21,10 @@ from pandas._libs.tslib import monthrange

from conversion cimport tz_convert_single, pydt_to_i8
from frequencies cimport get_freq_code
from nattype cimport NPY_NAT
Copy link
Contributor

Choose a reason for hiding this comment

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

add these in setup.py

return days_per_month_table[is_leapyear(year)][month - 1]


cdef inline int _year_add_months(pandas_datetimestruct dts, int months) nogil:
Copy link
Contributor

Choose a reason for hiding this comment

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

can de-privatize

@jreback jreback added Clean Frequency DateOffsets labels Nov 19, 2017
@codecov
Copy link

codecov bot commented Nov 20, 2017

Codecov Report

Merging #18375 into master will decrease coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18375      +/-   ##
==========================================
- Coverage   91.38%   91.32%   -0.07%     
==========================================
  Files         164      164              
  Lines       49797    49703      -94     
==========================================
- Hits        45508    45391     -117     
- Misses       4289     4312      +23
Flag Coverage Δ
#multiple 89.12% <100%> (-0.05%) ⬇️
#single 39.61% <35.71%> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/tseries/offsets.py 96.7% <100%> (-0.23%) ⬇️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/plotting/_converter.py 63.44% <0%> (-1.82%) ⬇️
pandas/core/indexes/interval.py 92.52% <0%> (-0.34%) ⬇️
pandas/core/frame.py 97.8% <0%> (-0.1%) ⬇️

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 a172ff9...d865d81. Read the comment docs.

@@ -577,7 +577,10 @@ def pxd(name):
'pyxfile': '_libs/tslibs/offsets',
'pxdfiles': ['_libs/src/util',
'_libs/tslibs/conversion',
'_libs/tslibs/frequencies']},
'_libs/tslibs/frequencies',
Copy link
Contributor

Choose a reason for hiding this comment

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

in future prs can reduce the tslib.pyx deps I think now that lots of things are moved out.

@jreback jreback added this to the 0.22.0 milestone Nov 20, 2017
@jreback jreback merged commit 8486c73 into pandas-dev:master Nov 20, 2017
def shift_months(int64_t[:] dtindex, int months, object day=None):
"""
Given an int64-based datetime index, shift all elements
specified number of months using DateOffset semantics
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 doc-string things as well (here just fix the formatting to numpydoc)

@jbrockmendel jbrockmendel deleted the tslibs-offsets-shift_months branch December 8, 2017 19:40
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