Skip to content

Commit 5393748

Browse files
committed
DEPR: Deprecate cdate_range merge into bdate_range
1 parent 408ecd2 commit 5393748

File tree

10 files changed

+260
-205
lines changed

10 files changed

+260
-205
lines changed

doc/source/api.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ Top-level dealing with datetimelike
218218
to_timedelta
219219
date_range
220220
bdate_range
221-
cdate_range
222221
period_range
223222
timedelta_range
224223
infer_freq

doc/source/timeseries.rst

Lines changed: 108 additions & 105 deletions
Large diffs are not rendered by default.

doc/source/whatsnew/v0.21.0.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ Other Enhancements
164164
- :func:`read_excel` raises ``ImportError`` with a better message if ``xlrd`` is not installed. (:issue:`17613`)
165165
- :func:`read_json` now accepts a ``chunksize`` parameter that can be used when ``lines=True``. If ``chunksize`` is passed, read_json now returns an iterator which reads in ``chunksize`` lines with each iteration. (:issue:`17048`)
166166
- :meth:`DataFrame.assign` will preserve the original order of ``**kwargs`` for Python 3.6+ users instead of sorting the column names
167+
- :func:`bdate_range` has gained ``weekmask`` and ``holidays`` parameters for constructing custom frequency date ranges (:issue:`17596`)
167168

168169

169170
.. _whatsnew_0210.api_breaking:
@@ -488,7 +489,7 @@ Additionally, DataFrames with datetime columns that were parsed by :func:`read_s
488489
Consistency of Range Functions
489490
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
490491

491-
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`).
492+
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`).
492493

493494
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.
494495

@@ -571,6 +572,7 @@ Deprecations
571572
- :func:`SeriesGroupBy.nth` has deprecated ``True`` in favor of ``'all'`` for its kwarg ``dropna`` (:issue:`11038`).
572573
- :func:`DataFrame.as_blocks` is deprecated, as this is exposing the internal implementation (:issue:`17302`)
573574
- ``pd.TimeGrouper`` is deprecated in favor of :class:`pandas.Grouper` (:issue:`16747`)
575+
- ``cdate_range`` has been deprecated in favor of :func:`bdate_range` (:issue:`17596`)
574576

575577
.. _whatsnew_0210.deprecations.argmin_min
576578

pandas/core/api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
PeriodIndex, NaT)
1717
from pandas.core.indexes.period import Period, period_range, pnow
1818
from pandas.core.indexes.timedeltas import Timedelta, timedelta_range
19-
from pandas.core.indexes.datetimes import (Timestamp, date_range, bdate_range,
20-
cdate_range)
19+
from pandas.core.indexes.datetimes import Timestamp, date_range, bdate_range
2120
from pandas.core.indexes.interval import Interval, interval_range
2221

2322
from pandas.core.series import Series

pandas/core/indexes/datetimes.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
is_period_dtype,
1818
is_bool_dtype,
1919
is_string_dtype,
20+
is_string_like,
2021
is_list_like,
2122
is_scalar,
2223
pandas_dtype,
@@ -37,7 +38,8 @@
3738
Resolution)
3839
from pandas.core.indexes.datetimelike import (
3940
DatelikeOps, TimelikeOps, DatetimeIndexOpsMixin)
40-
from pandas.tseries.offsets import DateOffset, generate_range, Tick, CDay
41+
from pandas.tseries.offsets import (
42+
DateOffset, generate_range, Tick, CDay, prefix_mapping)
4143
from pandas.core.tools.datetimes import (
4244
parse_time_string, normalize_date, to_time)
4345
from pandas.core.tools.timedeltas import to_timedelta
@@ -2049,7 +2051,8 @@ def date_range(start=None, end=None, periods=None, freq='D', tz=None,
20492051

20502052

20512053
def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
2052-
normalize=True, name=None, closed=None, **kwargs):
2054+
normalize=True, name=None, weekmask='Mon Tue Wed Thu Fri',
2055+
holidays=None, closed=None, **kwargs):
20532056
"""
20542057
Return a fixed frequency DatetimeIndex, with business day as the default
20552058
frequency
@@ -2071,6 +2074,19 @@ def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
20712074
Normalize start/end dates to midnight before generating date range
20722075
name : string, default None
20732076
Name of the resulting DatetimeIndex
2077+
weekmask : string, default 'Mon Tue Wed Thu Fri'
2078+
weekmask of valid business days, passed to ``numpy.busdaycalendar``,
2079+
only used when custom frequency strings are passed
2080+
2081+
.. versionadded:: 0.21.0
2082+
2083+
holidays : list-like or None, default None
2084+
list-like of dates to exclude from the set of valid business days,
2085+
passed to ``numpy.busdaycalendar``, only used when custom frequency
2086+
strings are passed
2087+
2088+
.. versionadded:: 0.21.0
2089+
20742090
closed : string, default None
20752091
Make the interval closed with respect to the given frequency to
20762092
the 'left', 'right', or both sides (None)
@@ -2088,6 +2104,16 @@ def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
20882104
rng : DatetimeIndex
20892105
"""
20902106

2107+
if is_string_like(freq) and freq.startswith('C'):
2108+
try:
2109+
freq = prefix_mapping[freq](holidays=holidays, weekmask=weekmask)
2110+
except (KeyError, TypeError):
2111+
msg = 'invalid custom frequency string: {freq}'.format(freq=freq)
2112+
raise ValueError(msg)
2113+
elif holidays or (weekmask != 'Mon Tue Wed Thu Fri'):
2114+
warnings.warn('a custom frequency string was not passed, ignoring '
2115+
'parameters: holidays, weekmask', UserWarning)
2116+
20912117
return DatetimeIndex(start=start, end=end, periods=periods,
20922118
freq=freq, tz=tz, normalize=normalize, name=name,
20932119
closed=closed, **kwargs)
@@ -2099,6 +2125,8 @@ def cdate_range(start=None, end=None, periods=None, freq='C', tz=None,
20992125
Return a fixed frequency DatetimeIndex, with CustomBusinessDay as the
21002126
default frequency
21012127
2128+
.. deprecated:: 0.21.0
2129+
21022130
Parameters
21032131
----------
21042132
start : string or datetime-like, default None
@@ -2137,6 +2165,9 @@ def cdate_range(start=None, end=None, periods=None, freq='C', tz=None,
21372165
-------
21382166
rng : DatetimeIndex
21392167
"""
2168+
warnings.warn("cdate_range is deprecated and will be removed in a future "
2169+
"version, instead use bdate_range(..., freq='{freq}')"
2170+
.format(freq=freq), FutureWarning, stacklevel=2)
21402171

21412172
if freq == 'C':
21422173
holidays = kwargs.pop('holidays', [])

pandas/tests/api/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TestPDApi(Base):
6363
# top-level functions
6464
funcs = ['bdate_range', 'concat', 'crosstab', 'cut',
6565
'date_range', 'interval_range', 'eval',
66-
'factorize', 'get_dummies', 'cdate_range',
66+
'factorize', 'get_dummies',
6767
'infer_freq', 'isna', 'isnull', 'lreshape',
6868
'melt', 'notna', 'notnull', 'offsets',
6969
'merge', 'merge_ordered', 'merge_asof',

0 commit comments

Comments
 (0)