From ebbfe8718790021ca512994b43d774dbd14d78b5 Mon Sep 17 00:00:00 2001 From: sinhrks Date: Sun, 30 Aug 2015 11:01:22 +0900 Subject: [PATCH] DEPR: Deprecate legacy offsets --- doc/source/timeseries.rst | 21 +-- doc/source/whatsnew/v0.17.0.txt | 1 + pandas/tseries/frequencies.py | 67 +++++-- pandas/tseries/offsets.py | 3 +- pandas/tseries/tests/test_frequencies.py | 19 +- pandas/tseries/tests/test_offsets.py | 19 +- pandas/tseries/tests/test_period.py | 225 ++++++++++++++++++----- pandas/tseries/tests/test_plotting.py | 2 +- 8 files changed, 280 insertions(+), 77 deletions(-) diff --git a/doc/source/timeseries.rst b/doc/source/timeseries.rst index 6f30ff3f51ad5..4394981abb8c3 100644 --- a/doc/source/timeseries.rst +++ b/doc/source/timeseries.rst @@ -656,7 +656,7 @@ apply the offset to each element. rng + DateOffset(months=2) s + DateOffset(months=2) s - DateOffset(months=2) - + If the offset class maps directly to a ``Timedelta`` (``Day``, ``Hour``, ``Minute``, ``Second``, ``Micro``, ``Milli``, ``Nano``) it can be used exactly like a ``Timedelta`` - see the @@ -670,7 +670,7 @@ used exactly like a ``Timedelta`` - see the td + Minute(15) Note that some offsets (such as ``BQuarterEnd``) do not have a -vectorized implementation. They can still be used but may +vectorized implementation. They can still be used but may calculate signficantly slower and will raise a ``PerformanceWarning`` .. ipython:: python @@ -882,10 +882,10 @@ frequencies. We will refer to these aliases as *offset aliases* "BAS", "business year start frequency" "BH", "business hour frequency" "H", "hourly frequency" - "T", "minutely frequency" + "T, min", "minutely frequency" "S", "secondly frequency" - "L", "milliseonds" - "U", "microseconds" + "L, ms", "milliseonds" + "U, us", "microseconds" "N", "nanoseconds" Combining Aliases @@ -953,11 +953,12 @@ These can be used as arguments to ``date_range``, ``bdate_range``, constructors for ``DatetimeIndex``, as well as various other timeseries-related functions in pandas. +.. _timeseries.legacyaliases: + Legacy Aliases ~~~~~~~~~~~~~~ -Note that prior to v0.8.0, time rules had a slightly different look. pandas -will continue to support the legacy time rules for the time being but it is -strongly recommended that you switch to using the new offset aliases. +Note that prior to v0.8.0, time rules had a slightly different look. These are +deprecated in v0.17.0, and removed in future version. .. csv-table:: :header: "Legacy Time Rule", "Offset Alias" @@ -987,9 +988,7 @@ strongly recommended that you switch to using the new offset aliases. "A\@OCT", "BA\-OCT" "A\@NOV", "BA\-NOV" "A\@DEC", "BA\-DEC" - "min", "T" - "ms", "L" - "us", "U" + As you can see, legacy quarterly and annual frequencies are business quarters and business year ends. Please also note the legacy time rule for milliseconds diff --git a/doc/source/whatsnew/v0.17.0.txt b/doc/source/whatsnew/v0.17.0.txt index 9f2ec43cb2ae3..1d16136dd6b4d 100644 --- a/doc/source/whatsnew/v0.17.0.txt +++ b/doc/source/whatsnew/v0.17.0.txt @@ -653,6 +653,7 @@ Deprecations ``DataFrame.add(other, fill_value=0)`` and ``DataFrame.mul(other, fill_value=1.)`` (:issue:`10735`). - ``TimeSeries`` deprecated in favor of ``Series`` (note that this has been alias since 0.13.0), (:issue:`10890`) +- Legacy offsets (like ``'A@JAN'``) listed in :ref:`here ` are deprecated (note that this has been alias since 0.8.0), (:issue:`10878`) - ``WidePanel`` deprecated in favor of ``Panel``, ``LongPanel`` in favor of ``DataFrame`` (note these have been aliases since < 0.11.0), (:issue:`10892`) .. _whatsnew_0170.prior_deprecations: diff --git a/pandas/tseries/frequencies.py b/pandas/tseries/frequencies.py index 85de5e083d6d9..7e5c3af43c861 100644 --- a/pandas/tseries/frequencies.py +++ b/pandas/tseries/frequencies.py @@ -2,6 +2,7 @@ from pandas.compat import range, long, zip from pandas import compat import re +import warnings import numpy as np @@ -335,10 +336,8 @@ def get_period_alias(offset_str): _rule_aliases = { # Legacy rules that will continue to map to their original values # essentially for the rest of time - 'WEEKDAY': 'B', 'EOM': 'BM', - 'W@MON': 'W-MON', 'W@TUE': 'W-TUE', 'W@WED': 'W-WED', @@ -346,18 +345,9 @@ def get_period_alias(offset_str): 'W@FRI': 'W-FRI', 'W@SAT': 'W-SAT', 'W@SUN': 'W-SUN', - 'W': 'W-SUN', - 'Q@JAN': 'BQ-JAN', 'Q@FEB': 'BQ-FEB', 'Q@MAR': 'BQ-MAR', - 'Q': 'Q-DEC', - - 'A': 'A-DEC', # YearEnd(month=12), - 'AS': 'AS-JAN', # YearBegin(month=1), - 'BA': 'BA-DEC', # BYearEnd(month=12), - 'BAS': 'BAS-JAN', # BYearBegin(month=1), - 'A@JAN': 'BA-JAN', 'A@FEB': 'BA-FEB', 'A@MAR': 'BA-MAR', @@ -370,8 +360,17 @@ def get_period_alias(offset_str): 'A@OCT': 'BA-OCT', 'A@NOV': 'BA-NOV', 'A@DEC': 'BA-DEC', +} + +_lite_rule_alias = { + 'W': 'W-SUN', + 'Q': 'Q-DEC', + + 'A': 'A-DEC', # YearEnd(month=12), + 'AS': 'AS-JAN', # YearBegin(month=1), + 'BA': 'BA-DEC', # BYearEnd(month=12), + 'BAS': 'BAS-JAN', # BYearBegin(month=1), - # lite aliases 'Min': 'T', 'min': 'T', 'ms': 'L', @@ -386,6 +385,7 @@ def get_period_alias(offset_str): # Note that _rule_aliases is not 1:1 (d[BA]==d[A@DEC]), and so traversal # order matters when constructing an inverse. we pick one. #2331 +# Used in get_legacy_offset_name _legacy_reverse_map = dict((v, k) for k, v in reversed(sorted(compat.iteritems(_rule_aliases)))) @@ -501,6 +501,9 @@ def get_base_alias(freqstr): _dont_uppercase = set(('MS', 'ms')) +_LEGACY_FREQ_WARNING = 'Freq "{0}" is deprecated, use "{1}" as alternative.' + + def get_offset(name): """ Return DateOffset object associated with rule name @@ -513,12 +516,26 @@ def get_offset(name): name = name.upper() if name in _rule_aliases: - name = _rule_aliases[name] + new = _rule_aliases[name] + warnings.warn(_LEGACY_FREQ_WARNING.format(name, new), + FutureWarning) + name = new elif name.lower() in _rule_aliases: - name = _rule_aliases[name.lower()] + new = _rule_aliases[name.lower()] + warnings.warn(_LEGACY_FREQ_WARNING.format(name, new), + FutureWarning) + name = new + + name = _lite_rule_alias.get(name, name) + name = _lite_rule_alias.get(name.lower(), name) + else: if name in _rule_aliases: - name = _rule_aliases[name] + new = _rule_aliases[name] + warnings.warn(_LEGACY_FREQ_WARNING.format(name, new), + FutureWarning) + name = new + name = _lite_rule_alias.get(name, name) if name not in _offset_map: try: @@ -561,6 +578,9 @@ def get_legacy_offset_name(offset): """ Return the pre pandas 0.8.0 name for the date offset """ + + # This only used in test_timeseries_legacy.py + name = offset.name return _legacy_reverse_map.get(name, name) @@ -754,10 +774,21 @@ def _period_alias_dictionary(): def _period_str_to_code(freqstr): # hack - freqstr = _rule_aliases.get(freqstr, freqstr) + if freqstr in _rule_aliases: + new = _rule_aliases[freqstr] + warnings.warn(_LEGACY_FREQ_WARNING.format(freqstr, new), + FutureWarning) + freqstr = new + freqstr = _lite_rule_alias.get(freqstr, freqstr) if freqstr not in _dont_uppercase: - freqstr = _rule_aliases.get(freqstr.lower(), freqstr) + lower = freqstr.lower() + if lower in _rule_aliases: + new = _rule_aliases[lower] + warnings.warn(_LEGACY_FREQ_WARNING.format(lower, new), + FutureWarning) + freqstr = new + freqstr = _lite_rule_alias.get(lower, freqstr) try: if freqstr not in _dont_uppercase: @@ -766,6 +797,8 @@ def _period_str_to_code(freqstr): except KeyError: try: alias = _period_alias_dict[freqstr] + warnings.warn(_LEGACY_FREQ_WARNING.format(freqstr, alias), + FutureWarning) except KeyError: raise ValueError("Unknown freqstr: %s" % freqstr) diff --git a/pandas/tseries/offsets.py b/pandas/tseries/offsets.py index 33faac153cce0..ec416efe1079f 100644 --- a/pandas/tseries/offsets.py +++ b/pandas/tseries/offsets.py @@ -2650,14 +2650,13 @@ def generate_range(start=None, end=None, periods=None, prefix_mapping['N'] = Nano - def _make_offset(key): """Gets offset based on key. KeyError if prefix is bad, ValueError if suffix is bad. All handled by `get_offset` in tseries/frequencies. Not public.""" if key is None: return None - split = key.replace('@', '-').split('-') + split = key.split('-') klass = prefix_mapping[split[0]] # handles case where there's no suffix (and will TypeError if too many '-') obj = klass._from_name(*split[1:]) diff --git a/pandas/tseries/tests/test_frequencies.py b/pandas/tseries/tests/test_frequencies.py index 68b65697918f4..070363460f791 100644 --- a/pandas/tseries/tests/test_frequencies.py +++ b/pandas/tseries/tests/test_frequencies.py @@ -529,9 +529,13 @@ def test_series(self): self.assertRaises(ValueError, lambda : frequencies.infer_freq(Series(['foo','bar']))) # cannot infer on PeriodIndex - for freq in [None, 'L', 'Y']: + for freq in [None, 'L']: s = Series(period_range('2013',periods=10,freq=freq)) self.assertRaises(TypeError, lambda : frequencies.infer_freq(s)) + for freq in ['Y']: + with tm.assert_produces_warning(FutureWarning): + s = Series(period_range('2013',periods=10,freq=freq)) + self.assertRaises(TypeError, lambda : frequencies.infer_freq(s)) # DateTimeIndex for freq in ['M', 'L', 'S']: @@ -543,6 +547,19 @@ def test_series(self): inferred = frequencies.infer_freq(s) self.assertEqual(inferred,'D') + def test_legacy_offset_warnings(self): + for k, v in compat.iteritems(frequencies._rule_aliases): + with tm.assert_produces_warning(FutureWarning): + result = frequencies.get_offset(k) + exp = frequencies.get_offset(v) + self.assertEqual(result, exp) + + with tm.assert_produces_warning(FutureWarning): + idx = date_range('2011-01-01', periods=5, freq=k) + exp = date_range('2011-01-01', periods=5, freq=v) + self.assert_index_equal(idx, exp) + + MONTHS = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'] diff --git a/pandas/tseries/tests/test_offsets.py b/pandas/tseries/tests/test_offsets.py index d364206017c7e..b3ec88f4d0988 100644 --- a/pandas/tseries/tests/test_offsets.py +++ b/pandas/tseries/tests/test_offsets.py @@ -3615,7 +3615,6 @@ def test_get_offset(): ('Bm', BMonthEnd()), ('W-MON', Week(weekday=0)), ('W-TUE', Week(weekday=1)), ('W-WED', Week(weekday=2)), ('W-THU', Week(weekday=3)), ('W-FRI', Week(weekday=4)), - ('w@Sat', Week(weekday=5)), ("RE-N-DEC-MON", makeFY5253NearestEndMonth(weekday=0, startingMonth=12)), ("RE-L-DEC-TUE", makeFY5253LastOfMonth(weekday=1, startingMonth=12)), ("REQ-L-MAR-TUE-4", makeFY5253LastOfMonthQuarter(weekday=1, startingMonth=3, qtr_with_extra_week=4)), @@ -3628,6 +3627,13 @@ def test_get_offset(): assert offset == expected, ("Expected %r to yield %r (actual: %r)" % (name, expected, offset)) +def test_get_offset_legacy(): + pairs = [('w@Sat', Week(weekday=5))] + for name, expected in pairs: + with tm.assert_produces_warning(FutureWarning): + offset = get_offset(name) + assert offset == expected, ("Expected %r to yield %r (actual: %r)" % + (name, expected, offset)) class TestParseTimeString(tm.TestCase): @@ -3663,11 +3669,18 @@ def test_get_standard_freq(): assert fstr == get_standard_freq('w') assert fstr == get_standard_freq('1w') assert fstr == get_standard_freq(('W', 1)) - assert fstr == get_standard_freq('WeEk') + + with tm.assert_produces_warning(FutureWarning): + result = get_standard_freq('WeEk') + assert fstr == result fstr = get_standard_freq('5Q') assert fstr == get_standard_freq('5q') - assert fstr == get_standard_freq('5QuarTer') + + with tm.assert_produces_warning(FutureWarning): + result = get_standard_freq('5QuarTer') + assert fstr == result + assert fstr == get_standard_freq(('q', 5)) diff --git a/pandas/tseries/tests/test_period.py b/pandas/tseries/tests/test_period.py index dca37d9ce164c..cdd9d036fcadc 100644 --- a/pandas/tseries/tests/test_period.py +++ b/pandas/tseries/tests/test_period.py @@ -437,7 +437,7 @@ def test_properties_monthly(self): def test_properties_weekly(self): # Test properties on Periods with daily frequency. - w_date = Period(freq='WK', year=2007, month=1, day=7) + w_date = Period(freq='W', year=2007, month=1, day=7) # assert_equal(w_date.year, 2007) assert_equal(w_date.quarter, 1) @@ -445,7 +445,22 @@ def test_properties_weekly(self): assert_equal(w_date.week, 1) assert_equal((w_date - 1).week, 52) assert_equal(w_date.days_in_month, 31) - assert_equal(Period(freq='WK', year=2012, month=2, day=1).days_in_month, 29) + assert_equal(Period(freq='W', year=2012, month=2, day=1).days_in_month, 29) + + def test_properties_weekly_legacy(self): + # Test properties on Periods with daily frequency. + with tm.assert_produces_warning(FutureWarning): + w_date = Period(freq='WK', year=2007, month=1, day=7) + # + assert_equal(w_date.year, 2007) + assert_equal(w_date.quarter, 1) + assert_equal(w_date.month, 1) + assert_equal(w_date.week, 1) + assert_equal((w_date - 1).week, 52) + assert_equal(w_date.days_in_month, 31) + with tm.assert_produces_warning(FutureWarning): + exp = Period(freq='WK', year=2012, month=2, day=1) + assert_equal(exp.days_in_month, 29) def test_properties_daily(self): # Test properties on Periods with daily frequency. @@ -613,8 +628,8 @@ def test_conv_annual(self): ival_A_to_Q_end = Period(freq='Q', year=2007, quarter=4) ival_A_to_M_start = Period(freq='M', year=2007, month=1) ival_A_to_M_end = Period(freq='M', year=2007, month=12) - ival_A_to_W_start = Period(freq='WK', year=2007, month=1, day=1) - ival_A_to_W_end = Period(freq='WK', year=2007, month=12, day=31) + ival_A_to_W_start = Period(freq='W', year=2007, month=1, day=1) + ival_A_to_W_end = Period(freq='W', year=2007, month=12, day=31) ival_A_to_B_start = Period(freq='B', year=2007, month=1, day=1) ival_A_to_B_end = Period(freq='B', year=2007, month=12, day=31) ival_A_to_D_start = Period(freq='D', year=2007, month=1, day=1) @@ -643,8 +658,8 @@ def test_conv_annual(self): assert_equal(ival_A.asfreq('Q', 'e'), ival_A_to_Q_end) assert_equal(ival_A.asfreq('M', 's'), ival_A_to_M_start) assert_equal(ival_A.asfreq('M', 'E'), ival_A_to_M_end) - assert_equal(ival_A.asfreq('WK', 'S'), ival_A_to_W_start) - assert_equal(ival_A.asfreq('WK', 'E'), ival_A_to_W_end) + assert_equal(ival_A.asfreq('W', 'S'), ival_A_to_W_start) + assert_equal(ival_A.asfreq('W', 'E'), ival_A_to_W_end) assert_equal(ival_A.asfreq('B', 'S'), ival_A_to_B_start) assert_equal(ival_A.asfreq('B', 'E'), ival_A_to_B_end) assert_equal(ival_A.asfreq('D', 'S'), ival_A_to_D_start) @@ -681,8 +696,8 @@ def test_conv_quarterly(self): ival_Q_to_A = Period(freq='A', year=2007) ival_Q_to_M_start = Period(freq='M', year=2007, month=1) ival_Q_to_M_end = Period(freq='M', year=2007, month=3) - ival_Q_to_W_start = Period(freq='WK', year=2007, month=1, day=1) - ival_Q_to_W_end = Period(freq='WK', year=2007, month=3, day=31) + ival_Q_to_W_start = Period(freq='W', year=2007, month=1, day=1) + ival_Q_to_W_end = Period(freq='W', year=2007, month=3, day=31) ival_Q_to_B_start = Period(freq='B', year=2007, month=1, day=1) ival_Q_to_B_end = Period(freq='B', year=2007, month=3, day=30) ival_Q_to_D_start = Period(freq='D', year=2007, month=1, day=1) @@ -711,8 +726,8 @@ def test_conv_quarterly(self): assert_equal(ival_Q.asfreq('M', 'S'), ival_Q_to_M_start) assert_equal(ival_Q.asfreq('M', 'E'), ival_Q_to_M_end) - assert_equal(ival_Q.asfreq('WK', 'S'), ival_Q_to_W_start) - assert_equal(ival_Q.asfreq('WK', 'E'), ival_Q_to_W_end) + assert_equal(ival_Q.asfreq('W', 'S'), ival_Q_to_W_start) + assert_equal(ival_Q.asfreq('W', 'E'), ival_Q_to_W_end) assert_equal(ival_Q.asfreq('B', 'S'), ival_Q_to_B_start) assert_equal(ival_Q.asfreq('B', 'E'), ival_Q_to_B_end) assert_equal(ival_Q.asfreq('D', 'S'), ival_Q_to_D_start) @@ -739,8 +754,8 @@ def test_conv_monthly(self): ival_M_end_of_quarter = Period(freq='M', year=2007, month=3) ival_M_to_A = Period(freq='A', year=2007) ival_M_to_Q = Period(freq='Q', year=2007, quarter=1) - ival_M_to_W_start = Period(freq='WK', year=2007, month=1, day=1) - ival_M_to_W_end = Period(freq='WK', year=2007, month=1, day=31) + ival_M_to_W_start = Period(freq='W', year=2007, month=1, day=1) + ival_M_to_W_end = Period(freq='W', year=2007, month=1, day=31) ival_M_to_B_start = Period(freq='B', year=2007, month=1, day=1) ival_M_to_B_end = Period(freq='B', year=2007, month=1, day=31) ival_M_to_D_start = Period(freq='D', year=2007, month=1, day=1) @@ -763,8 +778,8 @@ def test_conv_monthly(self): assert_equal(ival_M.asfreq('Q'), ival_M_to_Q) assert_equal(ival_M_end_of_quarter.asfreq('Q'), ival_M_to_Q) - assert_equal(ival_M.asfreq('WK', 'S'), ival_M_to_W_start) - assert_equal(ival_M.asfreq('WK', 'E'), ival_M_to_W_end) + assert_equal(ival_M.asfreq('W', 'S'), ival_M_to_W_start) + assert_equal(ival_M.asfreq('W', 'E'), ival_M_to_W_end) assert_equal(ival_M.asfreq('B', 'S'), ival_M_to_B_start) assert_equal(ival_M.asfreq('B', 'E'), ival_M_to_B_end) assert_equal(ival_M.asfreq('D', 'S'), ival_M_to_D_start) @@ -781,15 +796,15 @@ def test_conv_monthly(self): def test_conv_weekly(self): # frequency conversion tests: from Weekly Frequency - ival_W = Period(freq='WK', year=2007, month=1, day=1) + ival_W = Period(freq='W', year=2007, month=1, day=1) - ival_WSUN = Period(freq='WK', year=2007, month=1, day=7) - ival_WSAT = Period(freq='WK-SAT', year=2007, month=1, day=6) - ival_WFRI = Period(freq='WK-FRI', year=2007, month=1, day=5) - ival_WTHU = Period(freq='WK-THU', year=2007, month=1, day=4) - ival_WWED = Period(freq='WK-WED', year=2007, month=1, day=3) - ival_WTUE = Period(freq='WK-TUE', year=2007, month=1, day=2) - ival_WMON = Period(freq='WK-MON', year=2007, month=1, day=1) + ival_WSUN = Period(freq='W', year=2007, month=1, day=7) + ival_WSAT = Period(freq='W-SAT', year=2007, month=1, day=6) + ival_WFRI = Period(freq='W-FRI', year=2007, month=1, day=5) + ival_WTHU = Period(freq='W-THU', year=2007, month=1, day=4) + ival_WWED = Period(freq='W-WED', year=2007, month=1, day=3) + ival_WTUE = Period(freq='W-TUE', year=2007, month=1, day=2) + ival_WMON = Period(freq='W-MON', year=2007, month=1, day=1) ival_WSUN_to_D_start = Period(freq='D', year=2007, month=1, day=1) ival_WSUN_to_D_end = Period(freq='D', year=2007, month=1, day=7) @@ -806,9 +821,9 @@ def test_conv_weekly(self): ival_WMON_to_D_start = Period(freq='D', year=2006, month=12, day=26) ival_WMON_to_D_end = Period(freq='D', year=2007, month=1, day=1) - ival_W_end_of_year = Period(freq='WK', year=2007, month=12, day=31) - ival_W_end_of_quarter = Period(freq='WK', year=2007, month=3, day=31) - ival_W_end_of_month = Period(freq='WK', year=2007, month=1, day=31) + ival_W_end_of_year = Period(freq='W', year=2007, month=12, day=31) + ival_W_end_of_quarter = Period(freq='W', year=2007, month=3, day=31) + ival_W_end_of_month = Period(freq='W', year=2007, month=1, day=31) ival_W_to_A = Period(freq='A', year=2007) ival_W_to_Q = Period(freq='Q', year=2007, quarter=1) ival_W_to_M = Period(freq='M', year=2007, month=1) @@ -885,7 +900,128 @@ def test_conv_weekly(self): assert_equal(ival_W.asfreq('S', 'S'), ival_W_to_S_start) assert_equal(ival_W.asfreq('S', 'E'), ival_W_to_S_end) - assert_equal(ival_W.asfreq('WK'), ival_W) + assert_equal(ival_W.asfreq('W'), ival_W) + + def test_conv_weekly_legacy(self): + # frequency conversion tests: from Weekly Frequency + + with tm.assert_produces_warning(FutureWarning): + ival_W = Period(freq='WK', year=2007, month=1, day=1) + + with tm.assert_produces_warning(FutureWarning): + ival_WSUN = Period(freq='WK', year=2007, month=1, day=7) + with tm.assert_produces_warning(FutureWarning): + ival_WSAT = Period(freq='WK-SAT', year=2007, month=1, day=6) + with tm.assert_produces_warning(FutureWarning): + ival_WFRI = Period(freq='WK-FRI', year=2007, month=1, day=5) + with tm.assert_produces_warning(FutureWarning): + ival_WTHU = Period(freq='WK-THU', year=2007, month=1, day=4) + with tm.assert_produces_warning(FutureWarning): + ival_WWED = Period(freq='WK-WED', year=2007, month=1, day=3) + with tm.assert_produces_warning(FutureWarning): + ival_WTUE = Period(freq='WK-TUE', year=2007, month=1, day=2) + with tm.assert_produces_warning(FutureWarning): + ival_WMON = Period(freq='WK-MON', year=2007, month=1, day=1) + + ival_WSUN_to_D_start = Period(freq='D', year=2007, month=1, day=1) + ival_WSUN_to_D_end = Period(freq='D', year=2007, month=1, day=7) + ival_WSAT_to_D_start = Period(freq='D', year=2006, month=12, day=31) + ival_WSAT_to_D_end = Period(freq='D', year=2007, month=1, day=6) + ival_WFRI_to_D_start = Period(freq='D', year=2006, month=12, day=30) + ival_WFRI_to_D_end = Period(freq='D', year=2007, month=1, day=5) + ival_WTHU_to_D_start = Period(freq='D', year=2006, month=12, day=29) + ival_WTHU_to_D_end = Period(freq='D', year=2007, month=1, day=4) + ival_WWED_to_D_start = Period(freq='D', year=2006, month=12, day=28) + ival_WWED_to_D_end = Period(freq='D', year=2007, month=1, day=3) + ival_WTUE_to_D_start = Period(freq='D', year=2006, month=12, day=27) + ival_WTUE_to_D_end = Period(freq='D', year=2007, month=1, day=2) + ival_WMON_to_D_start = Period(freq='D', year=2006, month=12, day=26) + ival_WMON_to_D_end = Period(freq='D', year=2007, month=1, day=1) + + with tm.assert_produces_warning(FutureWarning): + ival_W_end_of_year = Period(freq='WK', year=2007, month=12, day=31) + with tm.assert_produces_warning(FutureWarning): + ival_W_end_of_quarter = Period(freq='WK', year=2007, month=3, day=31) + with tm.assert_produces_warning(FutureWarning): + ival_W_end_of_month = Period(freq='WK', year=2007, month=1, day=31) + ival_W_to_A = Period(freq='A', year=2007) + ival_W_to_Q = Period(freq='Q', year=2007, quarter=1) + ival_W_to_M = Period(freq='M', year=2007, month=1) + + if Period(freq='D', year=2007, month=12, day=31).weekday == 6: + ival_W_to_A_end_of_year = Period(freq='A', year=2007) + else: + ival_W_to_A_end_of_year = Period(freq='A', year=2008) + + if Period(freq='D', year=2007, month=3, day=31).weekday == 6: + ival_W_to_Q_end_of_quarter = Period(freq='Q', year=2007, + quarter=1) + else: + ival_W_to_Q_end_of_quarter = Period(freq='Q', year=2007, + quarter=2) + + if Period(freq='D', year=2007, month=1, day=31).weekday == 6: + ival_W_to_M_end_of_month = Period(freq='M', year=2007, month=1) + else: + ival_W_to_M_end_of_month = Period(freq='M', year=2007, month=2) + + ival_W_to_B_start = Period(freq='B', year=2007, month=1, day=1) + ival_W_to_B_end = Period(freq='B', year=2007, month=1, day=5) + ival_W_to_D_start = Period(freq='D', year=2007, month=1, day=1) + ival_W_to_D_end = Period(freq='D', year=2007, month=1, day=7) + ival_W_to_H_start = Period(freq='H', year=2007, month=1, day=1, + hour=0) + ival_W_to_H_end = Period(freq='H', year=2007, month=1, day=7, + hour=23) + ival_W_to_T_start = Period(freq='Min', year=2007, month=1, day=1, + hour=0, minute=0) + ival_W_to_T_end = Period(freq='Min', year=2007, month=1, day=7, + hour=23, minute=59) + ival_W_to_S_start = Period(freq='S', year=2007, month=1, day=1, + hour=0, minute=0, second=0) + ival_W_to_S_end = Period(freq='S', year=2007, month=1, day=7, + hour=23, minute=59, second=59) + + assert_equal(ival_W.asfreq('A'), ival_W_to_A) + assert_equal(ival_W_end_of_year.asfreq('A'), + ival_W_to_A_end_of_year) + assert_equal(ival_W.asfreq('Q'), ival_W_to_Q) + assert_equal(ival_W_end_of_quarter.asfreq('Q'), + ival_W_to_Q_end_of_quarter) + assert_equal(ival_W.asfreq('M'), ival_W_to_M) + assert_equal(ival_W_end_of_month.asfreq('M'), + ival_W_to_M_end_of_month) + + assert_equal(ival_W.asfreq('B', 'S'), ival_W_to_B_start) + assert_equal(ival_W.asfreq('B', 'E'), ival_W_to_B_end) + + assert_equal(ival_W.asfreq('D', 'S'), ival_W_to_D_start) + assert_equal(ival_W.asfreq('D', 'E'), ival_W_to_D_end) + + assert_equal(ival_WSUN.asfreq('D', 'S'), ival_WSUN_to_D_start) + assert_equal(ival_WSUN.asfreq('D', 'E'), ival_WSUN_to_D_end) + assert_equal(ival_WSAT.asfreq('D', 'S'), ival_WSAT_to_D_start) + assert_equal(ival_WSAT.asfreq('D', 'E'), ival_WSAT_to_D_end) + assert_equal(ival_WFRI.asfreq('D', 'S'), ival_WFRI_to_D_start) + assert_equal(ival_WFRI.asfreq('D', 'E'), ival_WFRI_to_D_end) + assert_equal(ival_WTHU.asfreq('D', 'S'), ival_WTHU_to_D_start) + assert_equal(ival_WTHU.asfreq('D', 'E'), ival_WTHU_to_D_end) + assert_equal(ival_WWED.asfreq('D', 'S'), ival_WWED_to_D_start) + assert_equal(ival_WWED.asfreq('D', 'E'), ival_WWED_to_D_end) + assert_equal(ival_WTUE.asfreq('D', 'S'), ival_WTUE_to_D_start) + assert_equal(ival_WTUE.asfreq('D', 'E'), ival_WTUE_to_D_end) + assert_equal(ival_WMON.asfreq('D', 'S'), ival_WMON_to_D_start) + assert_equal(ival_WMON.asfreq('D', 'E'), ival_WMON_to_D_end) + + assert_equal(ival_W.asfreq('H', 'S'), ival_W_to_H_start) + assert_equal(ival_W.asfreq('H', 'E'), ival_W_to_H_end) + assert_equal(ival_W.asfreq('Min', 'S'), ival_W_to_T_start) + assert_equal(ival_W.asfreq('Min', 'E'), ival_W_to_T_end) + assert_equal(ival_W.asfreq('S', 'S'), ival_W_to_S_start) + assert_equal(ival_W.asfreq('S', 'E'), ival_W_to_S_end) + + with tm.assert_produces_warning(FutureWarning): + assert_equal(ival_W.asfreq('WK'), ival_W) def test_conv_business(self): # frequency conversion tests: from Business Frequency" @@ -899,7 +1035,7 @@ def test_conv_business(self): ival_B_to_A = Period(freq='A', year=2007) ival_B_to_Q = Period(freq='Q', year=2007, quarter=1) ival_B_to_M = Period(freq='M', year=2007, month=1) - ival_B_to_W = Period(freq='WK', year=2007, month=1, day=7) + ival_B_to_W = Period(freq='W', year=2007, month=1, day=7) ival_B_to_D = Period(freq='D', year=2007, month=1, day=1) ival_B_to_H_start = Period(freq='H', year=2007, month=1, day=1, hour=0) @@ -920,8 +1056,8 @@ def test_conv_business(self): assert_equal(ival_B_end_of_quarter.asfreq('Q'), ival_B_to_Q) assert_equal(ival_B.asfreq('M'), ival_B_to_M) assert_equal(ival_B_end_of_month.asfreq('M'), ival_B_to_M) - assert_equal(ival_B.asfreq('WK'), ival_B_to_W) - assert_equal(ival_B_end_of_week.asfreq('WK'), ival_B_to_W) + assert_equal(ival_B.asfreq('W'), ival_B_to_W) + assert_equal(ival_B_end_of_week.asfreq('W'), ival_B_to_W) assert_equal(ival_B.asfreq('D'), ival_B_to_D) @@ -962,7 +1098,7 @@ def test_conv_daily(self): ival_D_to_QEDEC = Period(freq="Q-DEC", year=2007, quarter=1) ival_D_to_M = Period(freq='M', year=2007, month=1) - ival_D_to_W = Period(freq='WK', year=2007, month=1, day=7) + ival_D_to_W = Period(freq='W', year=2007, month=1, day=7) ival_D_to_H_start = Period(freq='H', year=2007, month=1, day=1, hour=0) @@ -993,8 +1129,8 @@ def test_conv_daily(self): assert_equal(ival_D.asfreq("Q-DEC"), ival_D_to_QEDEC) assert_equal(ival_D.asfreq('M'), ival_D_to_M) assert_equal(ival_D_end_of_month.asfreq('M'), ival_D_to_M) - assert_equal(ival_D.asfreq('WK'), ival_D_to_W) - assert_equal(ival_D_end_of_week.asfreq('WK'), ival_D_to_W) + assert_equal(ival_D.asfreq('W'), ival_D_to_W) + assert_equal(ival_D_end_of_week.asfreq('W'), ival_D_to_W) assert_equal(ival_D_friday.asfreq('B'), ival_B_friday) assert_equal(ival_D_saturday.asfreq('B', 'S'), ival_B_friday) @@ -1031,7 +1167,7 @@ def test_conv_hourly(self): ival_H_to_A = Period(freq='A', year=2007) ival_H_to_Q = Period(freq='Q', year=2007, quarter=1) ival_H_to_M = Period(freq='M', year=2007, month=1) - ival_H_to_W = Period(freq='WK', year=2007, month=1, day=7) + ival_H_to_W = Period(freq='W', year=2007, month=1, day=7) ival_H_to_D = Period(freq='D', year=2007, month=1, day=1) ival_H_to_B = Period(freq='B', year=2007, month=1, day=1) @@ -1050,8 +1186,8 @@ def test_conv_hourly(self): assert_equal(ival_H_end_of_quarter.asfreq('Q'), ival_H_to_Q) assert_equal(ival_H.asfreq('M'), ival_H_to_M) assert_equal(ival_H_end_of_month.asfreq('M'), ival_H_to_M) - assert_equal(ival_H.asfreq('WK'), ival_H_to_W) - assert_equal(ival_H_end_of_week.asfreq('WK'), ival_H_to_W) + assert_equal(ival_H.asfreq('W'), ival_H_to_W) + assert_equal(ival_H_end_of_week.asfreq('W'), ival_H_to_W) assert_equal(ival_H.asfreq('D'), ival_H_to_D) assert_equal(ival_H_end_of_day.asfreq('D'), ival_H_to_D) assert_equal(ival_H.asfreq('B'), ival_H_to_B) @@ -1087,7 +1223,7 @@ def test_conv_minutely(self): ival_T_to_A = Period(freq='A', year=2007) ival_T_to_Q = Period(freq='Q', year=2007, quarter=1) ival_T_to_M = Period(freq='M', year=2007, month=1) - ival_T_to_W = Period(freq='WK', year=2007, month=1, day=7) + ival_T_to_W = Period(freq='W', year=2007, month=1, day=7) ival_T_to_D = Period(freq='D', year=2007, month=1, day=1) ival_T_to_B = Period(freq='B', year=2007, month=1, day=1) ival_T_to_H = Period(freq='H', year=2007, month=1, day=1, hour=0) @@ -1103,8 +1239,8 @@ def test_conv_minutely(self): assert_equal(ival_T_end_of_quarter.asfreq('Q'), ival_T_to_Q) assert_equal(ival_T.asfreq('M'), ival_T_to_M) assert_equal(ival_T_end_of_month.asfreq('M'), ival_T_to_M) - assert_equal(ival_T.asfreq('WK'), ival_T_to_W) - assert_equal(ival_T_end_of_week.asfreq('WK'), ival_T_to_W) + assert_equal(ival_T.asfreq('W'), ival_T_to_W) + assert_equal(ival_T_end_of_week.asfreq('W'), ival_T_to_W) assert_equal(ival_T.asfreq('D'), ival_T_to_D) assert_equal(ival_T_end_of_day.asfreq('D'), ival_T_to_D) assert_equal(ival_T.asfreq('B'), ival_T_to_B) @@ -1142,7 +1278,7 @@ def test_conv_secondly(self): ival_S_to_A = Period(freq='A', year=2007) ival_S_to_Q = Period(freq='Q', year=2007, quarter=1) ival_S_to_M = Period(freq='M', year=2007, month=1) - ival_S_to_W = Period(freq='WK', year=2007, month=1, day=7) + ival_S_to_W = Period(freq='W', year=2007, month=1, day=7) ival_S_to_D = Period(freq='D', year=2007, month=1, day=1) ival_S_to_B = Period(freq='B', year=2007, month=1, day=1) ival_S_to_H = Period(freq='H', year=2007, month=1, day=1, @@ -1156,8 +1292,8 @@ def test_conv_secondly(self): assert_equal(ival_S_end_of_quarter.asfreq('Q'), ival_S_to_Q) assert_equal(ival_S.asfreq('M'), ival_S_to_M) assert_equal(ival_S_end_of_month.asfreq('M'), ival_S_to_M) - assert_equal(ival_S.asfreq('WK'), ival_S_to_W) - assert_equal(ival_S_end_of_week.asfreq('WK'), ival_S_to_W) + assert_equal(ival_S.asfreq('W'), ival_S_to_W) + assert_equal(ival_S_end_of_week.asfreq('W'), ival_S_to_W) assert_equal(ival_S.asfreq('D'), ival_S_to_D) assert_equal(ival_S_end_of_day.asfreq('D'), ival_S_to_D) assert_equal(ival_S.asfreq('B'), ival_S_to_B) @@ -2171,12 +2307,17 @@ def test_to_period_annualish(self): self.assertEqual(prng.freq, 'A-DEC') def test_to_period_monthish(self): - offsets = ['MS', 'EOM', 'BM'] + offsets = ['MS', 'BM'] for off in offsets: rng = date_range('01-Jan-2012', periods=8, freq=off) prng = rng.to_period() self.assertEqual(prng.freq, 'M') + with tm.assert_produces_warning(FutureWarning): + rng = date_range('01-Jan-2012', periods=8, freq='EOM') + prng = rng.to_period() + self.assertEqual(prng.freq, 'M') + def test_no_multiples(self): self.assertRaises(ValueError, period_range, '1989Q3', periods=10, freq='2Q') diff --git a/pandas/tseries/tests/test_plotting.py b/pandas/tseries/tests/test_plotting.py index 39736eef79295..08a4056c1fce2 100644 --- a/pandas/tseries/tests/test_plotting.py +++ b/pandas/tseries/tests/test_plotting.py @@ -22,7 +22,7 @@ @tm.mplskip class TestTSPlot(tm.TestCase): def setUp(self): - freq = ['S', 'T', 'H', 'D', 'W', 'M', 'Q', 'Y'] + freq = ['S', 'T', 'H', 'D', 'W', 'M', 'Q', 'A'] idx = [period_range('12/31/1999', freq=x, periods=100) for x in freq] self.period_ser = [Series(np.random.randn(len(x)), x) for x in idx] self.period_df = [DataFrame(np.random.randn(len(x), 3), index=x,