Skip to content

CLN: remove get_base_alias #34243

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
May 20, 2020
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
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/frequencies.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ cdef dict attrname_to_abbrevs
cpdef str get_rule_month(object source, str default=*)

cpdef get_freq_code(freqstr)
cpdef str get_base_alias(freqstr)
cpdef int get_to_timestamp_base(int base)
cpdef str get_freq_str(base, mult=*)
15 changes: 0 additions & 15 deletions pandas/_libs/tslibs/frequencies.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,6 @@ cpdef str get_freq_str(base, mult=1):
return str(mult) + code


cpdef str get_base_alias(freqstr):
"""
Returns the base frequency alias, e.g., '5D' -> 'D'

Parameters
----------
freqstr : str

Returns
-------
base_alias : str
"""
return base_and_stride(freqstr)[0]


cpdef int get_to_timestamp_base(int base):
"""
Return frequency code group used for base of to_timestamp against
Expand Down
5 changes: 1 addition & 4 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ from pandas._libs.tslibs.ccalendar cimport (
from pandas._libs.tslibs.ccalendar cimport c_MONTH_NUMBERS
from pandas._libs.tslibs.frequencies cimport (
attrname_to_abbrevs,
get_base_alias,
get_freq_code,
get_freq_str,
get_rule_month,
Expand Down Expand Up @@ -1600,9 +1599,7 @@ cdef class _Period:
raise IncompatibleFrequency("Input cannot be converted to "
f"Period(freq={self.freqstr})")
elif util.is_offset_object(other):
freqstr = other.rule_code
base = get_base_alias(freqstr)
if base == self.freq.rule_code:
if self.freq.base == other.base:
ordinal = self.ordinal + other.n
return Period(ordinal=ordinal, freq=self.freq)
msg = DIFFERENT_FREQ.format(cls=type(self).__name__,
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,10 @@ def _addsub_int_array(
res_values[self._isnan] = iNaT
return type(self)(res_values, freq=self.freq)

def _add_offset(self, other):
def _add_offset(self, other: DateOffset):
assert not isinstance(other, Tick)
base = libfrequencies.get_base_alias(other.rule_code)
if base != self.freq.rule_code:

if other.base != self.freq.base:
raise raise_on_incompatible(self, other)

# Note: when calling parent class's _add_timedeltalike_scalar,
Expand Down
31 changes: 15 additions & 16 deletions pandas/plotting/_matplotlib/timeseries.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# TODO: Use the fact that axis can have units to simplify the process

import functools
from typing import Optional

import numpy as np

from pandas._libs.tslibs.frequencies import (
FreqGroup,
get_base_alias,
base_and_stride,
get_freq_code,
is_subperiod,
is_superperiod,
Expand Down Expand Up @@ -165,6 +166,16 @@ def _get_ax_freq(ax):
return ax_freq


def get_period_alias(freq) -> Optional[str]:
Copy link
Member Author

Choose a reason for hiding this comment

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

@datapythonista suggestions for a docstring here? i dont know off the top of my head what this alias is used for.

if isinstance(freq, DateOffset):
freq = freq.rule_code
else:
freq = base_and_stride(freq)[0]

freq = frequencies.get_period_alias(freq)
return freq


def _get_freq(ax, series):
# get frequency from data
freq = getattr(series.index, "freq", None)
Expand All @@ -178,12 +189,7 @@ def _get_freq(ax, series):
freq = ax_freq

# get the period frequency
if isinstance(freq, DateOffset):
freq = freq.rule_code
else:
freq = get_base_alias(freq)

freq = frequencies.get_period_alias(freq)
freq = get_period_alias(freq)
return freq, ax_freq


Expand All @@ -200,11 +206,7 @@ def _use_dynamic_x(ax, data):
if freq is None:
return False

if isinstance(freq, DateOffset):
freq = freq.rule_code
else:
freq = get_base_alias(freq)
freq = frequencies.get_period_alias(freq)
freq = get_period_alias(freq)

if freq is None:
return False
Expand Down Expand Up @@ -238,17 +240,14 @@ def _maybe_convert_index(ax, data):

if freq is None:
freq = getattr(data.index, "inferred_freq", None)
if isinstance(freq, DateOffset):
freq = freq.rule_code

if freq is None:
freq = _get_ax_freq(ax)

if freq is None:
raise ValueError("Could not get frequency alias for plotting")

freq = get_base_alias(freq)
freq = frequencies.get_period_alias(freq)
freq = get_period_alias(freq)

if isinstance(data.index, ABCDatetimeIndex):
data = data.tz_localize(None).to_period(freq=freq)
Expand Down