Skip to content

Commit

Permalink
DEPR: Deprecate DateRange [fix pandas-dev#6816]
Browse files Browse the repository at this point in the history
  • Loading branch information
jsexauer authored and jeffreystarr committed Apr 28, 2014
1 parent 0781fe5 commit e762e41
Show file tree
Hide file tree
Showing 23 changed files with 25 additions and 115 deletions.
2 changes: 1 addition & 1 deletion bench/bench_dense_to_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
4 changes: 2 additions & 2 deletions bench/io_roundtrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'

Expand Down
2 changes: 2 additions & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,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
Expand Down
2 changes: 2 additions & 0 deletions doc/source/v0.14.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ Prior Version Deprecations/Changes

There 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`)

.. _whatsnew_0140.deprecations:
Expand Down
4 changes: 2 additions & 2 deletions examples/regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
1 change: 0 additions & 1 deletion pandas/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
48 changes: 0 additions & 48 deletions pandas/core/daterange.py

This file was deleted.

20 changes: 0 additions & 20 deletions pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3876,26 +3876,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
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions pandas/tseries/tests/test_timeseries_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -255,25 +254,6 @@ def test_rule_aliases(self):
rule = datetools.to_offset('10us')
self.assertEqual(rule, datetools.Micro(10))


class TestLegacyCompat(unittest.TestCase):

def setUp(self):
# suppress deprecation warnings
sys.stderr = StringIO()

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__


if __name__ == '__main__':
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
exit=False)
1 change: 0 additions & 1 deletion pandas/tseries/tests/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions scripts/bench_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions scripts/groupby_speed.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion scripts/hdfstore_panel_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])

Expand Down
2 changes: 1 addition & 1 deletion scripts/preepoch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
2 changes: 1 addition & 1 deletion vb_suite/index_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions vb_suite/panel_ctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vb_suite/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"""

Expand Down
2 changes: 1 addition & 1 deletion vb_suite/reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion vb_suite/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions vb_suite/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e762e41

Please sign in to comment.