8000 [REF] Move comparison methods to EAMixins, share code by jbrockmendel · Pull Request #21872 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

[REF] Move comparison methods to EAMixins, share code #21872

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 17 commits into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
de-privatize _quarter_to_myear
  • Loading branch information
jbrockmendel committed Jul 12, 2018
commit fbf1e6e7686dc73af60ba91972ebc165db469a2f
26 changes: 24 additions & 2 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1860,13 +1860,33 @@ cdef int64_t _ordinal_from_fields(year, month, quarter, day,
hour, minute, second, freq):
base, mult = get_freq_code(freq)
if quarter is not None:
year, month = _quarter_to_myear(year, quarter, freq)
year, month = quarter_to_myear(year, quarter, freq)

return period_ordinal(year, month, day, hour,
minute, second, 0, 0, base)


def _quarter_to_myear(year, quarter, freq):
def quarter_to_myear(year, quarter, freq):
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally type these, where is quarter passed as None?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is used once in period.pyx and once in arrays.period, always with quarter non-None. I'll make that required.

"""
A quarterly frequency defines a "year" which may not coincide with
the calendar-year. Find the calendar-year and calendar-month associated
with the given year and quarter under the `freq`-derived calendar.

Parameters
----------
year : int
quarter : int
freq : DateOffset

Returns
-------
year : int
month : int

See Also
--------
Period.qyear
"""
if quarter is not None:
if quarter <= 0 or quarter > 4:
raise ValueError('Quarter must be 1 <= q <= 4')
Expand All @@ -1877,6 +1897,8 @@ def _quarter_to_myear(year, quarter, freq):
year -= 1

return year, month
# FIXME: if quarter is None then `month` won't be defined here.
# just disallow quarter == None?
Copy link
Member

Choose a reason for hiding this comment

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



def _validate_end_alias(how):
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pandas._libs.tslib import NaT, iNaT
from pandas._libs.tslibs.period import (
Period, IncompatibleFrequency, DIFFERENT_FREQ_INDEX,
get_period_field_arr, period_asfreq_arr, _quarter_to_myear)
get_period_field_arr, period_asfreq_arr)
from pandas._libs.tslibs import period as libperiod
from pandas._libs.tslibs.timedeltas import delta_to_nanoseconds
from pandas._libs.tslibs.fields import isleapyear_arr
Expand Down Expand Up @@ -466,7 +466,7 @@ def _range_from_fields(year=None, month=None, quarter=None, day=None,

year, quarter = _make_field_arrays(year, quarter)
for y, q in compat.zip(year, quarter):
y, m = _quarter_to_myear(y, q, freq)
y, m = libperiod.quarter_to_myear(y, q, freq)
val = libperiod.period_ordinal(y, m, 1, 1, 1, 1, 0, 0, base)
ordinals.append(val)
else:
Expand Down
3084
0