From d459269dcbca93db96eb7df84f6d7eb3ee6bd426 Mon Sep 17 00:00:00 2001 From: Jason Sexauer Date: Sat, 5 Apr 2014 21:51:05 -0400 Subject: [PATCH] DEPR: Deprecate DateRange [fix #6816] --- bench/bench_dense_to_sparse.py | 2 +- bench/io_roundtrip.py | 4 +- doc/source/release.rst | 2 + doc/source/v0.14.0.txt | 2 + examples/regressions.py | 4 +- pandas/core/api.py | 1 - pandas/core/daterange.py | 48 ------------------- pandas/core/index.py | 20 -------- pandas/core/internals.py | 4 +- pandas/core/series.py | 3 +- pandas/tseries/tests/test_timeseries.py | 1 - .../tseries/tests/test_timeseries_legacy.py | 9 ---- pandas/tseries/tests/test_timezones.py | 1 - scripts/bench_join.py | 4 +- scripts/groupby_speed.py | 4 +- scripts/hdfstore_panel_perf.py | 2 +- scripts/preepoch_test.py | 2 +- vb_suite/index_object.py | 2 +- vb_suite/panel_ctor.py | 4 +- vb_suite/plotting.py | 2 +- vb_suite/reindex.py | 2 +- vb_suite/replace.py | 2 +- vb_suite/timeseries.py | 4 +- 23 files changed, 25 insertions(+), 104 deletions(-) delete mode 100644 pandas/core/daterange.py diff --git a/bench/bench_dense_to_sparse.py b/bench/bench_dense_to_sparse.py index f76daab5d8289..e1dcd3456e88d 100644 --- a/bench/bench_dense_to_sparse.py +++ b/bench/bench_dense_to_sparse.py @@ -2,7 +2,7 @@ K = 100 N = 100000 -rng = DateRange('1/1/2000', periods=N, offset=datetools.Minute()) +rng = DatetimeIndex('1/1/2000', periods=N, offset=datetools.Minute()) rng2 = np.asarray(rng).astype('M8[us]').astype('i8') diff --git a/bench/io_roundtrip.py b/bench/io_roundtrip.py index fa4e0755f40df..d87da0ec6321a 100644 --- a/bench/io_roundtrip.py +++ b/bench/io_roundtrip.py @@ -6,7 +6,7 @@ import la import pandas from pandas.compat import range -from pandas import datetools, DateRange +from pandas import datetools, DatetimeIndex def timeit(f, iterations): @@ -23,7 +23,7 @@ def rountrip_archive(N, K=50, iterations=10): arr = np.random.randn(N, K) # lar = la.larry(arr) dma = pandas.DataFrame(arr, - DateRange('1/1/2000', periods=N, + DatetimeIndex('1/1/2000', periods=N, offset=datetools.Minute())) dma[201] = 'bar' diff --git a/doc/source/release.rst b/doc/source/release.rst index 7188851214f7f..64604e918688d 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -180,6 +180,8 @@ Deprecations Prior Version Deprecations/Changes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +- Remove :class:`DateRange` in favor of :class:`DatetimeIndex` (:issue:`6816`) + - Remove ``column`` keyword from ``DataFrame.sort`` (:issue:`4370`) Experimental Features diff --git a/doc/source/v0.14.0.txt b/doc/source/v0.14.0.txt index 23ab8f10116c1..e53a1e5126db1 100644 --- a/doc/source/v0.14.0.txt +++ b/doc/source/v0.14.0.txt @@ -326,6 +326,8 @@ Prior Version Deprecations/Changes Therse are prior version deprecations that are taking effect as of 0.14.0. +- Remove :class:`DateRange` in favor of :class:`DatetimeIndex` (:issue:`6816`) + - Remove ``column`` keyword from ``DataFrame.sort`` (:issue:`4370`) Deprecations diff --git a/examples/regressions.py b/examples/regressions.py index 6351c6730d838..bc58408a6842b 100644 --- a/examples/regressions.py +++ b/examples/regressions.py @@ -3,13 +3,13 @@ import numpy as np -from pandas.core.api import Series, DataFrame, DateRange +from pandas.core.api import Series, DataFrame, DatetimeIndex from pandas.stats.api import ols N = 100 start = datetime(2009, 9, 2) -dateRange = DateRange(start, periods=N) +dateRange = DatetimeIndex(start, periods=N) def makeDataFrame(): diff --git a/pandas/core/api.py b/pandas/core/api.py index 3ebcb46cd98fa..b7e02917cd476 100644 --- a/pandas/core/api.py +++ b/pandas/core/api.py @@ -28,7 +28,6 @@ from pandas.tseries.period import Period, PeriodIndex # legacy -from pandas.core.daterange import DateRange # deprecated from pandas.core.common import save, load # deprecated, remove in 0.13 import pandas.core.datetools as datetools diff --git a/pandas/core/daterange.py b/pandas/core/daterange.py deleted file mode 100644 index bdaf546789c39..0000000000000 --- a/pandas/core/daterange.py +++ /dev/null @@ -1,48 +0,0 @@ -# pylint: disable=E1101,E1103 - -from pandas.core.index import Index -from pandas.tseries.index import DatetimeIndex -import pandas.core.datetools as datetools - - -#----------------------------------------------------------------------------- -# DateRange class - -class DateRange(Index): - - """Deprecated - """ - - offset = tzinfo = None - - def __new__(cls, start=None, end=None, periods=None, - offset=datetools.bday, time_rule=None, - tzinfo=None, name=None, **kwds): - - import warnings - warnings.warn("DateRange is deprecated, use DatetimeIndex instead", - FutureWarning) - - if time_rule is None: - time_rule = kwds.get('timeRule') - if time_rule is not None: - offset = datetools.get_offset(time_rule) - - return DatetimeIndex(start=start, end=end, - periods=periods, freq=offset, - tzinfo=tzinfo, name=name, **kwds) - - def __setstate__(self, aug_state): - """Necessary for making this object picklable""" - index_state = aug_state[:1] - offset = aug_state[1] - - # for backwards compatibility - if len(aug_state) > 2: - tzinfo = aug_state[2] - else: # pragma: no cover - tzinfo = None - - self.offset = offset - self.tzinfo = tzinfo - Index.__setstate__(self, *index_state) diff --git a/pandas/core/index.py b/pandas/core/index.py index bae4a2c455ec6..c162365a39bf8 100644 --- a/pandas/core/index.py +++ b/pandas/core/index.py @@ -3888,26 +3888,6 @@ def _sanitize_and_check(indexes): return indexes, 'array' -def _handle_legacy_indexes(indexes): - from pandas.core.daterange import DateRange - from pandas.tseries.index import DatetimeIndex - - converted = [] - for index in indexes: - if isinstance(index, DateRange): - if len(index) == 0: - kwds = dict(data=[], freq=index.offset, tz=index.tzinfo) - else: - kwds = dict(start=index[0], end=index[-1], - freq=index.offset, tz=index.tzinfo) - - index = DatetimeIndex(**kwds) - - converted.append(index) - - return converted - - def _get_consensus_names(indexes): # find the non-none names, need to tupleify to make diff --git a/pandas/core/internals.py b/pandas/core/internals.py index e28d4029d4fa0..0560480a9c2db 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -12,8 +12,7 @@ _NS_DTYPE, _TD_DTYPE, ABCSeries, is_list_like, ABCSparseSeries, _infer_dtype_from_scalar, _values_from_object, _is_null_datelike_scalar) -from pandas.core.index import (Index, MultiIndex, _ensure_index, - _handle_legacy_indexes) +from pandas.core.index import Index, MultiIndex, _ensure_index from pandas.core.indexing import (_maybe_convert_indices, _length_of_indexer) import pandas.core.common as com from pandas.sparse.array import _maybe_to_sparse, SparseArray @@ -2369,7 +2368,6 @@ def __setstate__(self, state): ax_arrays, bvalues, bitems = state[:3] self.axes = [_ensure_index(ax) for ax in ax_arrays] - self.axes = _handle_legacy_indexes(self.axes) blocks = [] for values, items in zip(bvalues, bitems): diff --git a/pandas/core/series.py b/pandas/core/series.py index 4ab7855ec2f84..763d14b629508 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -26,7 +26,7 @@ _ensure_object, SettingWithCopyError) from pandas.core.index import (Index, MultiIndex, InvalidIndexError, - _ensure_index, _handle_legacy_indexes) + _ensure_index) from pandas.core.indexing import ( _check_bool_indexer, _is_index_slice, _maybe_convert_indices) @@ -426,7 +426,6 @@ def _unpickle_series_compat(self, state): index, name = own_state[0], None if len(own_state) > 1: name = own_state[1] - index = _handle_legacy_indexes([index])[0] # recreate self._data = SingleBlockManager(data, index, fastpath=True) diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index 64da6f76f3697..1bcf6c0b4431a 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -15,7 +15,6 @@ isnull, date_range, Timestamp, Period, DatetimeIndex, Int64Index, to_datetime, bdate_range, Float64Index) -from pandas.core.daterange import DateRange import pandas.core.datetools as datetools import pandas.tseries.offsets as offsets import pandas.tseries.tools as tools diff --git a/pandas/tseries/tests/test_timeseries_legacy.py b/pandas/tseries/tests/test_timeseries_legacy.py index 3155f0f6e1a80..f9c031576f554 100644 --- a/pandas/tseries/tests/test_timeseries_legacy.py +++ b/pandas/tseries/tests/test_timeseries_legacy.py @@ -13,7 +13,6 @@ isnull, date_range, Timestamp, DatetimeIndex, Int64Index, to_datetime, bdate_range) -from pandas.core.daterange import DateRange import pandas.core.datetools as datetools import pandas.tseries.offsets as offsets import pandas.tseries.frequencies as fmod @@ -284,14 +283,6 @@ def test_inferTimeRule(self): self.assertRaises(Exception, inferTimeRule, index1[:2]) self.assertRaises(Exception, inferTimeRule, index3) - def test_time_rule(self): - result = DateRange('1/1/2000', '1/30/2000', time_rule='WEEKDAY') - result2 = DateRange('1/1/2000', '1/30/2000', timeRule='WEEKDAY') - expected = date_range('1/1/2000', '1/30/2000', freq='B') - - self.assert_(result.equals(expected)) - self.assert_(result2.equals(expected)) - def tearDown(self): sys.stderr = sys.__stderr__ diff --git a/pandas/tseries/tests/test_timezones.py b/pandas/tseries/tests/test_timezones.py index dda722366e53e..245a21eb2c112 100644 --- a/pandas/tseries/tests/test_timezones.py +++ b/pandas/tseries/tests/test_timezones.py @@ -12,7 +12,6 @@ from pandas import DatetimeIndex, Int64Index, to_datetime, NaT -from pandas.core.daterange import DateRange import pandas.core.datetools as datetools import pandas.tseries.offsets as offsets from pandas.tseries.index import bdate_range, date_range diff --git a/scripts/bench_join.py b/scripts/bench_join.py index c9f2475566519..5223aac40d63b 100644 --- a/scripts/bench_join.py +++ b/scripts/bench_join.py @@ -12,8 +12,8 @@ a = np.arange(n, dtype=np.int64) b = np.arange(n * pct_overlap, n * (1 + pct_overlap), dtype=np.int64) -dr1 = DateRange('1/1/2000', periods=n, offset=datetools.Minute()) -dr2 = DateRange( +dr1 = DatetimeIndex('1/1/2000', periods=n, offset=datetools.Minute()) +dr2 = DatetimeIndex( dr1[int(pct_overlap * n)], periods=n, offset=datetools.Minute(2)) aobj = a.astype(object) diff --git a/scripts/groupby_speed.py b/scripts/groupby_speed.py index 4e60c34556968..34f293d5008c6 100644 --- a/scripts/groupby_speed.py +++ b/scripts/groupby_speed.py @@ -1,12 +1,12 @@ from __future__ import print_function from pandas import * -rng = DateRange('1/3/2011', '11/30/2011', offset=datetools.Minute()) +rng = DatetimeIndex('1/3/2011', '11/30/2011', offset=datetools.Minute()) df = DataFrame(np.random.randn(len(rng), 5), index=rng, columns=list('OHLCV')) -rng5 = DateRange('1/3/2011', '11/30/2011', offset=datetools.Minute(5)) +rng5 = DatetimeIndex('1/3/2011', '11/30/2011', offset=datetools.Minute(5)) gp = rng5.asof grouped = df.groupby(gp) diff --git a/scripts/hdfstore_panel_perf.py b/scripts/hdfstore_panel_perf.py index 06c2a15bdc7c2..66b0b52444bc1 100644 --- a/scripts/hdfstore_panel_perf.py +++ b/scripts/hdfstore_panel_perf.py @@ -6,7 +6,7 @@ panel = Panel(np.random.randn(i, j, k), items=[rands(10) for _ in range(i)], - major_axis=DateRange('1/1/2000', periods=j, + major_axis=DatetimeIndex('1/1/2000', periods=j, offset=datetools.Minute()), minor_axis=[rands(10) for _ in range(k)]) diff --git a/scripts/preepoch_test.py b/scripts/preepoch_test.py index 59066ba832cd0..36a3d768e671f 100644 --- a/scripts/preepoch_test.py +++ b/scripts/preepoch_test.py @@ -7,7 +7,7 @@ def panda_test(): # generate some data data = np.random.rand(50, 5) # generate some dates - dates = DateRange('1/1/1969', periods=50) + dates = DatetimeIndex('1/1/1969', periods=50) # generate column headings cols = ['A', 'B', 'C', 'D', 'E'] diff --git a/vb_suite/index_object.py b/vb_suite/index_object.py index 2cfdffdc38541..cb13d63cd726c 100644 --- a/vb_suite/index_object.py +++ b/vb_suite/index_object.py @@ -11,7 +11,7 @@ # intersection, union setup = common_setup + """ -rng = DateRange('1/1/2000', periods=10000, offset=datetools.Minute()) +rng = DatetimeIndex('1/1/2000', periods=10000, offset=datetools.Minute()) if rng.dtype == object: rng = rng.view(Index) else: diff --git a/vb_suite/panel_ctor.py b/vb_suite/panel_ctor.py index 07d7326ecb879..e304a48e5d73f 100644 --- a/vb_suite/panel_ctor.py +++ b/vb_suite/panel_ctor.py @@ -11,7 +11,7 @@ setup_same_index = common_setup + """ # create 100 dataframes with the same index -dr = np.asarray(DateRange(datetime(1990,1,1), datetime(2012,1,1))) +dr = np.asarray(DatetimeIndex(datetime(1990,1,1), datetime(2012,1,1))) data_frames = {} for x in xrange(100): df = DataFrame({"a": [0]*len(dr), "b": [1]*len(dr), @@ -27,7 +27,7 @@ setup_equiv_indexes = common_setup + """ data_frames = {} for x in xrange(100): - dr = np.asarray(DateRange(datetime(1990,1,1), datetime(2012,1,1))) + dr = np.asarray(DatetimeIndex(datetime(1990,1,1), datetime(2012,1,1))) df = DataFrame({"a": [0]*len(dr), "b": [1]*len(dr), "c": [2]*len(dr)}, index=dr) data_frames[x] = df diff --git a/vb_suite/plotting.py b/vb_suite/plotting.py index 735ed78c1441e..88d272e7be4b3 100644 --- a/vb_suite/plotting.py +++ b/vb_suite/plotting.py @@ -7,7 +7,7 @@ from pandas import date_range except ImportError: def date_range(start=None, end=None, periods=None, freq=None): - return DateRange(start, end, periods=periods, offset=freq) + return DatetimeIndex(start, end, periods=periods, offset=freq) """ diff --git a/vb_suite/reindex.py b/vb_suite/reindex.py index de0f397334e94..ca82ee9b82649 100644 --- a/vb_suite/reindex.py +++ b/vb_suite/reindex.py @@ -18,7 +18,7 @@ #---------------------------------------------------------------------- setup = common_setup + """ -rng = DateRange('1/1/1970', periods=10000, offset=datetools.Minute()) +rng = DatetimeIndex('1/1/1970', periods=10000, offset=datetools.Minute()) df = DataFrame(np.random.rand(10000, 10), index=rng, columns=range(10)) df['foo'] = 'bar' diff --git a/vb_suite/replace.py b/vb_suite/replace.py index 517e2da599694..50ab9f429a471 100644 --- a/vb_suite/replace.py +++ b/vb_suite/replace.py @@ -9,7 +9,7 @@ try: rng = date_range('1/1/2000', periods=N, freq='min') except NameError: - rng = DateRange('1/1/2000', periods=N, offset=datetools.Minute()) + rng = DatetimeIndex('1/1/2000', periods=N, offset=datetools.Minute()) date_range = DateRange ts = Series(np.random.randn(N), index=rng) diff --git a/vb_suite/timeseries.py b/vb_suite/timeseries.py index ccd4bd7ae371a..3ea970baeff7a 100644 --- a/vb_suite/timeseries.py +++ b/vb_suite/timeseries.py @@ -8,9 +8,9 @@ try: rng = date_range('1/1/2000', periods=N, freq='min') except NameError: - rng = DateRange('1/1/2000', periods=N, offset=datetools.Minute()) + rng = DatetimeIndex('1/1/2000', periods=N, offset=datetools.Minute()) def date_range(start=None, end=None, periods=None, freq=None): - return DateRange(start, end, periods=periods, offset=freq) + return DatetimeIndex(start, end, periods=periods, offset=freq) if hasattr(Series, 'convert'): Series.resample = Series.convert