Skip to content

Commit

Permalink
DEPR: Deprecate cdate_range merge into bdate_range
Browse files Browse the repository at this point in the history
  • Loading branch information
jschendel committed Sep 27, 2017
1 parent d3be81a commit eb38d12
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 205 deletions.
1 change: 0 additions & 1 deletion doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ Top-level dealing with datetimelike
to_timedelta
date_range
bdate_range
cdate_range
period_range
timedelta_range
infer_freq
Expand Down
213 changes: 108 additions & 105 deletions doc/source/timeseries.rst

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ Other Enhancements
- :func:`Categorical.rename_categories` now accepts a dict-like argument as `new_categories` and only updates the categories found in that dict. (:issue:`17336`)
- :func:`read_excel` raises ``ImportError`` with a better message if ``xlrd`` is not installed. (:issue:`17613`)
- :meth:`DataFrame.assign` will preserve the original order of ``**kwargs`` for Python 3.6+ users instead of sorting the column names
- :func:`bdate_range` has gained ``weekmask`` and ``holidays`` parameters for constructing custom frequency date ranges (:issue:`17596`)


.. _whatsnew_0210.api_breaking:
Expand Down Expand Up @@ -411,7 +412,7 @@ Additionally, DataFrames with datetime columns that were parsed by :func:`read_s
Consistency of Range Functions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

In previous versions, there were some inconsistencies between the various range functions: :func:`date_range`, :func:`bdate_range`, :func:`cdate_range`, :func:`period_range`, :func:`timedelta_range`, and :func:`interval_range`. (:issue:`17471`).
In previous versions, there were some inconsistencies between the various range functions: :func:`date_range`, :func:`bdate_range`, :func:`period_range`, :func:`timedelta_range`, and :func:`interval_range`. (:issue:`17471`).

One of the inconsistent behaviors occurred when the ``start``, ``end`` and ``period`` parameters were all specified, potentially leading to ambiguous ranges. When all three parameters were passed, ``interval_range`` ignored the ``period`` parameter, ``period_range`` ignored the ``end`` parameter, and the other range functions raised. To promote consistency among the range functions, and avoid potentially ambiguous ranges, ``interval_range`` and ``period_range`` will now raise when all three parameters are passed.

Expand Down Expand Up @@ -491,6 +492,7 @@ Deprecations
- ``pd.options.html.border`` has been deprecated in favor of ``pd.options.display.html.border`` (:issue:`15793`).
- :func:`SeriesGroupBy.nth` has deprecated ``True`` in favor of ``'all'`` for its kwarg ``dropna`` (:issue:`11038`).
- :func:`DataFrame.as_blocks` is deprecated, as this is exposing the internal implementation (:issue:`17302`)
- ``cdate_range`` has been deprecated in favor of :func:`bdate_range` (:issue:`17596`)

.. _whatsnew_0210.prior_deprecations:

Expand Down
3 changes: 1 addition & 2 deletions pandas/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
PeriodIndex, NaT)
from pandas.core.indexes.period import Period, period_range, pnow
from pandas.core.indexes.timedeltas import Timedelta, timedelta_range
from pandas.core.indexes.datetimes import (Timestamp, date_range, bdate_range,
cdate_range)
from pandas.core.indexes.datetimes import Timestamp, date_range, bdate_range
from pandas.core.indexes.interval import Interval, interval_range

from pandas.core.series import Series
Expand Down
35 changes: 33 additions & 2 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
is_period_dtype,
is_bool_dtype,
is_string_dtype,
is_string_like,
is_list_like,
is_scalar,
pandas_dtype,
Expand All @@ -37,7 +38,8 @@
Resolution)
from pandas.core.indexes.datetimelike import (
DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin)
from pandas.tseries.offsets import DateOffset, generate_range, Tick, CDay
from pandas.tseries.offsets import (
DateOffset, generate_range, Tick, CDay, prefix_mapping)
from pandas.core.tools.datetimes import (
parse_time_string, normalize_date, to_time)
from pandas.core.tools.timedeltas import to_timedelta
Expand Down Expand Up @@ -2049,7 +2051,8 @@ def date_range(start=None, end=None, periods=None, freq='D', tz=None,


def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
normalize=True, name=None, closed=None, **kwargs):
normalize=True, name=None, weekmask='Mon Tue Wed Thu Fri',
holidays=None, closed=None, **kwargs):
"""
Return a fixed frequency DatetimeIndex, with business day as the default
frequency
Expand All @@ -2071,6 +2074,19 @@ def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
Normalize start/end dates to midnight before generating date range
name : string, default None
Name of the resulting DatetimeIndex
weekmask : string, default 'Mon Tue Wed Thu Fri'
weekmask of valid business days, passed to ``numpy.busdaycalendar``,
only used when custom frequency strings are passed
.. versionadded:: 0.21.0
holidays : list-like or None, default None
list-like of dates to exclude from the set of valid business days,
passed to ``numpy.busdaycalendar``, only used when custom frequency
strings are passed
.. versionadded:: 0.21.0
closed : string, default None
Make the interval closed with respect to the given frequency to
the 'left', 'right', or both sides (None)
Expand All @@ -2088,6 +2104,16 @@ def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
rng : DatetimeIndex
"""

if is_string_like(freq) and freq.startswith('C'):
try:
freq = prefix_mapping[freq](holidays=holidays, weekmask=weekmask)
except (KeyError, TypeError):
msg = 'invalid custom frequency string: {freq}'.format(freq=freq)
raise ValueError(msg)
elif holidays or (weekmask != 'Mon Tue Wed Thu Fri'):
warnings.warn('a custom frequency string was not passed, ignoring '
'parameters: holidays, weekmask', UserWarning)

return DatetimeIndex(start=start, end=end, periods=periods,
freq=freq, tz=tz, normalize=normalize, name=name,
closed=closed, **kwargs)
Expand All @@ -2099,6 +2125,8 @@ def cdate_range(start=None, end=None, periods=None, freq='C', tz=None,
Return a fixed frequency DatetimeIndex, with CustomBusinessDay as the
default frequency
.. deprecated:: 0.21.0
Parameters
----------
start : string or datetime-like, default None
Expand Down Expand Up @@ -2137,6 +2165,9 @@ def cdate_range(start=None, end=None, periods=None, freq='C', tz=None,
-------
rng : DatetimeIndex
"""
warnings.warn("cdate_range is deprecated and will be removed in a future "
"version, instead use bdate_range(..., freq='{freq}')"
.format(freq=freq), FutureWarning, stacklevel=2)

if freq == 'C':
holidays = kwargs.pop('holidays', [])
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TestPDApi(Base):
# top-level functions
funcs = ['bdate_range', 'concat', 'crosstab', 'cut',
'date_range', 'interval_range', 'eval',
'factorize', 'get_dummies', 'cdate_range',
'factorize', 'get_dummies',
'infer_freq', 'isna', 'isnull', 'lreshape',
'melt', 'notna', 'notnull', 'offsets',
'merge', 'merge_ordered', 'merge_asof',
Expand Down
Loading

0 comments on commit eb38d12

Please sign in to comment.