Skip to content

Commit

Permalink
remove unused imports from tseries.frequencies; update imports elsewh…
Browse files Browse the repository at this point in the history
…ere (#24834)
  • Loading branch information
jbrockmendel authored and jreback committed Jan 19, 2019
1 parent f78790f commit f4458c1
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 136 deletions.
29 changes: 15 additions & 14 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import numpy as np

from pandas._libs.tslibs import NaT, iNaT, period as libperiod
from pandas._libs.tslibs import (
NaT, frequencies as libfrequencies, iNaT, period as libperiod)
from pandas._libs.tslibs.fields import isleapyear_arr
from pandas._libs.tslibs.period import (
DIFFERENT_FREQ, IncompatibleFrequency, Period, get_period_field_arr,
Expand All @@ -31,7 +32,7 @@

def _field_accessor(name, alias, docstring=None):
def f(self):
base, mult = frequencies.get_freq_code(self.freq)
base, mult = libfrequencies.get_freq_code(self.freq)
result = get_period_field_arr(alias, self.asi8, base)
return result

Expand Down Expand Up @@ -348,12 +349,12 @@ def to_timestamp(self, freq=None, how='start'):
return (self + self.freq).to_timestamp(how='start') - adjust

if freq is None:
base, mult = frequencies.get_freq_code(self.freq)
freq = frequencies.get_to_timestamp_base(base)
base, mult = libfrequencies.get_freq_code(self.freq)
freq = libfrequencies.get_to_timestamp_base(base)
else:
freq = Period._maybe_convert_freq(freq)

base, mult = frequencies.get_freq_code(freq)
base, mult = libfrequencies.get_freq_code(freq)
new_data = self.asfreq(freq, how=how)

new_data = libperiod.periodarr_to_dt64arr(new_data.asi8, base)
Expand Down Expand Up @@ -450,8 +451,8 @@ def asfreq(self, freq=None, how='E'):

freq = Period._maybe_convert_freq(freq)

base1, mult1 = frequencies.get_freq_code(self.freq)
base2, mult2 = frequencies.get_freq_code(freq)
base1, mult1 = libfrequencies.get_freq_code(self.freq)
base2, mult2 = libfrequencies.get_freq_code(freq)

asi8 = self.asi8
# mult1 can't be negative or 0
Expand Down Expand Up @@ -551,7 +552,7 @@ def _addsub_int_array(

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

Expand Down Expand Up @@ -855,7 +856,7 @@ def dt64arr_to_periodarr(data, freq, tz=None):
if isinstance(data, (ABCIndexClass, ABCSeries)):
data = data._values

base, mult = frequencies.get_freq_code(freq)
base, mult = libfrequencies.get_freq_code(freq)
return libperiod.dt64arr_to_periodarr(data.view('i8'), base, tz), freq


Expand All @@ -865,7 +866,7 @@ def _get_ordinal_range(start, end, periods, freq, mult=1):
'exactly two must be specified')

if freq is not None:
_, mult = frequencies.get_freq_code(freq)
_, mult = libfrequencies.get_freq_code(freq)

if start is not None:
start = Period(start, freq)
Expand Down Expand Up @@ -919,10 +920,10 @@ def _range_from_fields(year=None, month=None, quarter=None, day=None,
if quarter is not None:
if freq is None:
freq = 'Q'
base = frequencies.FreqGroup.FR_QTR
base = libfrequencies.FreqGroup.FR_QTR
else:
base, mult = frequencies.get_freq_code(freq)
if base != frequencies.FreqGroup.FR_QTR:
base, mult = libfrequencies.get_freq_code(freq)
if base != libfrequencies.FreqGroup.FR_QTR:
raise AssertionError("base must equal FR_QTR")

year, quarter = _make_field_arrays(year, quarter)
Expand All @@ -931,7 +932,7 @@ def _range_from_fields(year=None, month=None, quarter=None, day=None,
val = libperiod.period_ordinal(y, m, 1, 1, 1, 1, 0, 0, base)
ordinals.append(val)
else:
base, mult = frequencies.get_freq_code(freq)
base, mult = libfrequencies.get_freq_code(freq)
arrays = _make_field_arrays(year, month, day, hour, minute, second)
for y, mth, d, h, mn, s in compat.zip(*arrays):
ordinals.append(libperiod.period_ordinal(
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import numpy as np

from pandas._libs import index as libindex
from pandas._libs.tslibs import NaT, iNaT, resolution
from pandas._libs.tslibs import (
NaT, frequencies as libfrequencies, iNaT, resolution)
from pandas._libs.tslibs.period import (
DIFFERENT_FREQ, IncompatibleFrequency, Period)
from pandas.util._decorators import Appender, Substitution, cache_readonly
Expand Down Expand Up @@ -376,7 +377,7 @@ def _maybe_convert_timedelta(self, other):
return delta
elif isinstance(other, DateOffset):
freqstr = other.rule_code
base = frequencies.get_base_alias(freqstr)
base = libfrequencies.get_base_alias(freqstr)
if base == self.freq.rule_code:
return other.n

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from pandas._libs import lib
from pandas._libs.tslibs import NaT, Timestamp
from pandas._libs.tslibs.frequencies import is_subperiod, is_superperiod
from pandas._libs.tslibs.period import IncompatibleFrequency
import pandas.compat as compat
from pandas.compat.numpy import function as nv
Expand All @@ -28,7 +29,7 @@
from pandas.core.indexes.period import PeriodIndex
from pandas.core.indexes.timedeltas import TimedeltaIndex, timedelta_range

from pandas.tseries.frequencies import is_subperiod, is_superperiod, to_offset
from pandas.tseries.frequencies import to_offset
from pandas.tseries.offsets import (
DateOffset, Day, Nano, Tick, delta_to_nanoseconds)

Expand Down
10 changes: 4 additions & 6 deletions pandas/plotting/_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from pandas._libs import lib, tslibs
from pandas._libs.tslibs import resolution
from pandas._libs.tslibs.frequencies import FreqGroup, get_freq
import pandas.compat as compat
from pandas.compat import lrange

Expand All @@ -25,9 +26,6 @@
from pandas.core.indexes.period import Period, PeriodIndex, period_range
import pandas.core.tools.datetimes as tools

import pandas.tseries.frequencies as frequencies
from pandas.tseries.frequencies import FreqGroup

# constants
HOURS_PER_DAY = 24.
MIN_PER_HOUR = 60.
Expand Down Expand Up @@ -955,7 +953,7 @@ def _annual_finder(vmin, vmax, freq):

def get_finder(freq):
if isinstance(freq, compat.string_types):
freq = frequencies.get_freq(freq)
freq = get_freq(freq)
fgroup = resolution.get_freq_group(freq)

if fgroup == FreqGroup.FR_ANN:
Expand Down Expand Up @@ -992,7 +990,7 @@ class TimeSeries_DateLocator(Locator):
def __init__(self, freq, minor_locator=False, dynamic_mode=True,
base=1, quarter=1, month=1, day=1, plot_obj=None):
if isinstance(freq, compat.string_types):
freq = frequencies.get_freq(freq)
freq = get_freq(freq)
self.freq = freq
self.base = base
(self.quarter, self.month, self.day) = (quarter, month, day)
Expand Down Expand Up @@ -1073,7 +1071,7 @@ class TimeSeries_DateFormatter(Formatter):
def __init__(self, freq, minor_locator=False, dynamic_mode=True,
plot_obj=None):
if isinstance(freq, compat.string_types):
freq = frequencies.get_freq(freq)
freq = get_freq(freq)
self.format = None
self.freq = freq
self.locs = []
Expand Down
24 changes: 13 additions & 11 deletions pandas/plotting/_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from matplotlib import pylab
import numpy as np

from pandas._libs.tslibs.frequencies import (
FreqGroup, get_base_alias, get_freq, is_subperiod, is_superperiod)
from pandas._libs.tslibs.period import Period
import pandas.compat as compat

Expand Down Expand Up @@ -73,7 +75,7 @@ def _maybe_resample(series, ax, kwargs):
series = series.to_period(freq=freq)

if ax_freq is not None and freq != ax_freq:
if frequencies.is_superperiod(freq, ax_freq): # upsample input
if is_superperiod(freq, ax_freq): # upsample input
series = series.copy()
series.index = series.index.asfreq(ax_freq, how='s')
freq = ax_freq
Expand All @@ -82,21 +84,21 @@ def _maybe_resample(series, ax, kwargs):
series = getattr(series.resample('D'), how)().dropna()
series = getattr(series.resample(ax_freq), how)().dropna()
freq = ax_freq
elif frequencies.is_subperiod(freq, ax_freq) or _is_sub(freq, ax_freq):
elif is_subperiod(freq, ax_freq) or _is_sub(freq, ax_freq):
_upsample_others(ax, freq, kwargs)
else: # pragma: no cover
raise ValueError('Incompatible frequency conversion')
return freq, series


def _is_sub(f1, f2):
return ((f1.startswith('W') and frequencies.is_subperiod('D', f2)) or
(f2.startswith('W') and frequencies.is_subperiod(f1, 'D')))
return ((f1.startswith('W') and is_subperiod('D', f2)) or
(f2.startswith('W') and is_subperiod(f1, 'D')))


def _is_sup(f1, f2):
return ((f1.startswith('W') and frequencies.is_superperiod('D', f2)) or
(f2.startswith('W') and frequencies.is_superperiod(f1, 'D')))
return ((f1.startswith('W') and is_superperiod('D', f2)) or
(f2.startswith('W') and is_superperiod(f1, 'D')))


def _upsample_others(ax, freq, kwargs):
Expand Down Expand Up @@ -209,7 +211,7 @@ def _get_freq(ax, series):
if isinstance(freq, DateOffset):
freq = freq.rule_code
else:
freq = frequencies.get_base_alias(freq)
freq = get_base_alias(freq)

freq = frequencies.get_period_alias(freq)
return freq, ax_freq
Expand All @@ -231,17 +233,17 @@ def _use_dynamic_x(ax, data):
if isinstance(freq, DateOffset):
freq = freq.rule_code
else:
freq = frequencies.get_base_alias(freq)
freq = get_base_alias(freq)
freq = frequencies.get_period_alias(freq)

if freq is None:
return False

# hack this for 0.10.1, creating more technical debt...sigh
if isinstance(data.index, ABCDatetimeIndex):
base = frequencies.get_freq(freq)
base = get_freq(freq)
x = data.index
if (base <= frequencies.FreqGroup.FR_DAY):
if (base <= FreqGroup.FR_DAY):
return x[:1].is_normalized
return Period(x[0], freq).to_timestamp(tz=x.tz) == x[0]
return True
Expand Down Expand Up @@ -275,7 +277,7 @@ def _maybe_convert_index(ax, data):
if freq is None:
raise ValueError('Could not get frequency alias for plotting')

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

data = data.to_period(freq=freq)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/datetimes/test_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ def test_construction_with_ndarray(self):
dates = [datetime(2013, 10, 7),
datetime(2013, 10, 8),
datetime(2013, 10, 9)]
data = DatetimeIndex(dates, freq=pd.tseries.frequencies.BDay()).values
result = DatetimeIndex(data, freq=pd.tseries.frequencies.BDay())
data = DatetimeIndex(dates, freq=pd.offsets.BDay()).values
result = DatetimeIndex(data, freq=pd.offsets.BDay())
expected = DatetimeIndex(['2013-10-07',
'2013-10-08',
'2013-10-09'],
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def test_astype_categorical_to_other(self):
tm.assert_series_equal(s.astype('category'), expected)
tm.assert_series_equal(s.astype(CategoricalDtype()), expected)
msg = (r"could not convert string to float: '(0 - 499|9500 - 9999)'|"
r"invalid literal for float\(\): 9500 - 9999")
r"invalid literal for float\(\): (0 - 499|9500 - 9999)")
with pytest.raises(ValueError, match=msg):
s.astype('float64')

Expand Down
Loading

0 comments on commit f4458c1

Please sign in to comment.