Skip to content

Commit 3d58a51

Browse files
committed
review updates
1 parent 5393748 commit 3d58a51

File tree

4 files changed

+63
-35
lines changed

4 files changed

+63
-35
lines changed

doc/source/timeseries.rst

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Class Remarks How to create
8888
.. _timeseries.representation:
8989

9090
Timestamps vs. Time Spans
91-
--------------------------
91+
-------------------------
9292

9393
Timestamped data is the most basic type of time series data that associates
9494
values with points in time. For pandas objects it means using the points in
@@ -263,12 +263,10 @@ pandas supports converting integer or float epoch times to ``Timestamp`` and
263263
``DatetimeIndex``. The default unit is nanoseconds, since that is how ``Timestamp``
264264
objects are stored internally. However, epochs are often stored in another ``unit``
265265
which can be specified. These are computed from the starting point specified by the
266-
:ref:`Origin Parameter <timeseries.origin>`.
266+
``origin`` parameter.
267267

268268
.. ipython:: python
269269
270-
pd.Timestamp(1349720105, unit='s')
271-
272270
pd.to_datetime([1349720105, 1349806505, 1349892905,
273271
1349979305, 1350065705], unit='s')
274272
@@ -292,6 +290,10 @@ which can be specified. These are computed from the starting point specified by
292290
pd.to_datetime([1490195805.433, 1490195805.433502912], unit='s')
293291
pd.to_datetime(1490195805433502912, unit='ns')
294292
293+
.. seealso::
294+
295+
:ref:`timeseries.origin`
296+
295297
.. _timeseries.converting.epoch_inverse:
296298

297299
From Timestamps to Epoch
@@ -312,8 +314,8 @@ We convert the ``DatetimeIndex`` to an ``int64`` array, then divide by the conve
312314
313315
.. _timeseries.origin:
314316

315-
Using the Origin Parameter
316-
~~~~~~~~~~~~~~~~~~~~~~~~~~
317+
Using the ``origin`` Parameter
318+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
317319

318320
.. versionadded:: 0.20.0
319321

@@ -353,7 +355,7 @@ To generate an index with timestamps, you can use either the ``DatetimeIndex`` o
353355
354356
In practice this becomes very cumbersome because we often need a very long
355357
index with a large number of timestamps. If we need timestamps on a regular
356-
frequency, we can use the ``date_range`` and ``bdate_range`` functions
358+
frequency, we can use the :func:`date_range` and :func:`bdate_range` functions
357359
to create a ``DatetimeIndex``. The default frequency for ``date_range`` is a
358360
**calendar day** while the default for ``bdate_range`` is a **business day**:
359361

@@ -392,11 +394,16 @@ of those specified will not be generated:
392394
393395
pd.bdate_range(start=start, periods=20)
394396
397+
.. _timeseries.custom-freq-ranges:
398+
399+
Custom Frequency Ranges
400+
~~~~~~~~~~~~~~~~~~~~~~~
401+
395402
.. versionadded:: 0.21.0
396403

397404
``bdate_range`` can also generate a range of custom frequency dates by using
398405
the ``weekmask`` and ``holidays`` parameters. These parameters will only be
399-
used if a custom frequency string is passed:
406+
used if a custom frequency string is passed.
400407

401408
.. ipython:: python
402409
@@ -406,8 +413,19 @@ used if a custom frequency string is passed:
406413
407414
pd.bdate_range(start, end, freq='C', weekmask=weekmask, holidays=holidays)
408415
409-
See the :ref:`Custom Business Days <timeseries.custombusinessdays>` section for
410-
additional information on custom frequencies.
416+
pd.bdate_range(start, end, freq='CBMS', weekmask=weekmask)
417+
418+
.. warning::
419+
420+
This functionality was originally exclusive to ``cdate_range``, which is
421+
deprecated as of version 0.21.0 in favor of ``bdate_range``. Note that
422+
``cdate_range`` only utilizes the ``weekmask`` and ``holidays`` parameters
423+
when custom business day, 'C', is passed as the frequency string. Support has
424+
been expanded with ``bdate_range`` to work with any custom frequency string.
425+
426+
.. seealso::
427+
428+
:ref:`timeseries.custombusinessdays`
411429

412430
.. _timeseries.timestamp-limits:
413431

@@ -422,7 +440,9 @@ can be represented using a 64-bit integer is limited to approximately 584 years:
422440
pd.Timestamp.min
423441
pd.Timestamp.max
424442
425-
See :ref:`here <timeseries.oob>` for ways to represent data outside these bound.
443+
.. seealso::
444+
445+
:ref:`timeseries.oob`
426446

427447
.. _timeseries.datetimeindex:
428448

doc/source/whatsnew/v0.21.0.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ 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`)
168167

169168

170169
.. _whatsnew_0210.api_breaking:
@@ -572,9 +571,9 @@ Deprecations
572571
- :func:`SeriesGroupBy.nth` has deprecated ``True`` in favor of ``'all'`` for its kwarg ``dropna`` (:issue:`11038`).
573572
- :func:`DataFrame.as_blocks` is deprecated, as this is exposing the internal implementation (:issue:`17302`)
574573
- ``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`)
574+
- ``cdate_range`` has been deprecated in favor of :func:`bdate_range`, which has gained ``weekmask`` and ``holidays`` parameters for building custom frequency date ranges. See the :ref:`documentation <timeseries.custom-freq-ranges>` for more details (:issue:`17596`)
576575

577-
.. _whatsnew_0210.deprecations.argmin_min
576+
.. _whatsnew_0210.deprecations.argmin_min:
578577

579578
Series.argmax and Series.argmin
580579
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -740,9 +739,9 @@ Numeric
740739

741740
Categorical
742741
^^^^^^^^^^^
743-
- Bug in :func:`Series.isin` when called with a categorical (:issue`16639`)
742+
- Bug in :func:`Series.isin` when called with a categorical (:issue:`16639`)
744743
- Bug in the categorical constructor with empty values and categories causing the ``.categories`` to be an empty ``Float64Index`` rather than an empty ``Index`` with object dtype (:issue:`17248`)
745-
- Bug in categorical operations with :ref:`Series.cat <categorical.cat>' not preserving the original Series' name (:issue:`17509`)
744+
- Bug in categorical operations with :ref:`Series.cat <categorical.cat>` not preserving the original Series' name (:issue:`17509`)
746745

747746
PyPy
748747
^^^^

pandas/core/indexes/datetimes.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,8 +2051,8 @@ def date_range(start=None, end=None, periods=None, freq='D', tz=None,
20512051

20522052

20532053
def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
2054-
normalize=True, name=None, weekmask='Mon Tue Wed Thu Fri',
2055-
holidays=None, closed=None, **kwargs):
2054+
normalize=True, name=None, weekmask=None, holidays=None,
2055+
closed=None, **kwargs):
20562056
"""
20572057
Return a fixed frequency DatetimeIndex, with business day as the default
20582058
frequency
@@ -2074,16 +2074,17 @@ def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
20742074
Normalize start/end dates to midnight before generating date range
20752075
name : string, default None
20762076
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
2077+
weekmask : string or None, default None
2078+
Weekmask of valid business days, passed to ``numpy.busdaycalendar``,
2079+
only used when custom frequency strings are passed. The default
2080+
value None is equivalent to 'Mon Tue Wed Thu Fri'
20802081
20812082
.. versionadded:: 0.21.0
20822083
20832084
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
2085+
Dates to exclude from the set of valid business days, passed to
2086+
``numpy.busdaycalendar``, only used when custom frequency strings
2087+
are passed
20872088
20882089
.. versionadded:: 0.21.0
20892090
@@ -2106,13 +2107,15 @@ def bdate_range(start=None, end=None, periods=None, freq='B', tz=None,
21062107

21072108
if is_string_like(freq) and freq.startswith('C'):
21082109
try:
2110+
weekmask = weekmask or 'Mon Tue Wed Thu Fri'
21092111
freq = prefix_mapping[freq](holidays=holidays, weekmask=weekmask)
21102112
except (KeyError, TypeError):
21112113
msg = 'invalid custom frequency string: {freq}'.format(freq=freq)
21122114
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)
2115+
elif holidays or weekmask:
2116+
msg = ('a custom frequency string is required when holidays or '
2117+
'weekmask are passed, got frequency {freq}').format(freq=freq)
2118+
raise ValueError(msg)
21162119

21172120
return DatetimeIndex(start=start, end=end, periods=periods,
21182121
freq=freq, tz=tz, normalize=normalize, name=name,
@@ -2166,7 +2169,7 @@ def cdate_range(start=None, end=None, periods=None, freq='C', tz=None,
21662169
rng : DatetimeIndex
21672170
"""
21682171
warnings.warn("cdate_range is deprecated and will be removed in a future "
2169-
"version, instead use bdate_range(..., freq='{freq}')"
2172+
"version, instead use pd.bdate_range(..., freq='{freq}')"
21702173
.format(freq=freq), FutureWarning, stacklevel=2)
21712174

21722175
if freq == 'C':

pandas/tests/indexes/datetimes/test_date_range.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,10 @@ def test_cdaterange_weekmask(self):
589589
expected = DatetimeIndex(['2013-05-01', '2013-05-02', '2013-05-05'])
590590
tm.assert_index_equal(result, expected)
591591

592-
# warning with non-custom freq
593-
with tm.assert_produces_warning(UserWarning):
592+
# raise with non-custom freq
593+
msg = ('a custom frequency string is required when holidays or '
594+
'weekmask are passed, got frequency B')
595+
with tm.assert_raises_regex(ValueError, msg):
594596
bdate_range('2013-05-01', periods=3,
595597
weekmask='Sun Mon Tue Wed Thu')
596598

@@ -600,8 +602,10 @@ def test_cdaterange_holidays(self):
600602
expected = DatetimeIndex(['2013-05-02', '2013-05-03', '2013-05-06'])
601603
tm.assert_index_equal(result, expected)
602604

603-
# warning with non-custom freq
604-
with tm.assert_produces_warning(UserWarning):
605+
# raise with non-custom freq
606+
msg = ('a custom frequency string is required when holidays or '
607+
'weekmask are passed, got frequency B')
608+
with tm.assert_raises_regex(ValueError, msg):
605609
bdate_range('2013-05-01', periods=3, holidays=['2013-05-01'])
606610

607611
def test_cdaterange_weekmask_and_holidays(self):
@@ -611,8 +615,10 @@ def test_cdaterange_weekmask_and_holidays(self):
611615
expected = DatetimeIndex(['2013-05-02', '2013-05-05', '2013-05-06'])
612616
tm.assert_index_equal(result, expected)
613617

614-
# warning with non-custom freq
615-
with tm.assert_produces_warning(UserWarning):
618+
# raise with non-custom freq
619+
msg = ('a custom frequency string is required when holidays or '
620+
'weekmask are passed, got frequency B')
621+
with tm.assert_raises_regex(ValueError, msg):
616622
bdate_range('2013-05-01', periods=3,
617623
weekmask='Sun Mon Tue Wed Thu',
618624
holidays=['2013-05-01'])
@@ -629,7 +635,7 @@ def test_all_custom_freq(self, freq):
629635
with tm.assert_raises_regex(ValueError, msg.format(freq=bad_freq)):
630636
bdate_range(START, END, freq=bad_freq)
631637

632-
def test_depr_cdaterange(self):
638+
def test_deprecation_cdaterange(self):
633639
# GH17596
634640
with tm.assert_produces_warning(FutureWarning):
635641
cdate_range(START, END)

0 commit comments

Comments
 (0)