DEPR: Deprecate cdate_range and merge into bdate_range by jschendel · Pull Request #17691 · pandas-dev/pandas (original) (raw)

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation37 Commits3 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

jschendel

A bit going on here, so see summary below.

Deprecated cdate_range:

Expanded functionality of bdate_range:

Edits to timeseries.rst:

@codecov

jreback

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks pretty good

.. _timeseries.representation:
Time Stamps vs. Time Spans
Timestamps vs. Time Spans

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

underlines should match the length exactly

``DatetimeIndex``. The default unit is nanoseconds, since that is how ``Timestamp``
objects are stored internally. However, epochs are often stored in another ``unit``
which can be specified. These are computed from the starting point specified by the
:ref:`Origin Parameter <timeseries.origin>`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use origin

@@ -402,15 +392,29 @@ using various combinations of parameters like ``start``, ``end``,
pd.bdate_range(start=start, periods=20)
The start and end dates are strictly inclusive. So it will not generate any

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put a small ::warning box where you say cdate_range is deprecated, add a ref as well (then you can refer to it in whatsnew)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the appropriate location in this file

@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to deprecation section, mention the deprecation, and include a ref

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combine with the previous

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 '

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise here, this is invalid

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this can raise.

@@ -525,20 +524,18 @@ def test_freq_divides_end_in_nanos(self):
class TestCustomDateRange(object):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separately, most of these classes could actually be a hierarchy instead to share some code (or could parametrize things), but separate / later PR.

with tm.assert_raises_regex(ValueError, msg.format(freq=bad_freq)):
bdate_range(START, END, freq=bad_freq)
def test_depr_cdaterange(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecation

jorisvandenbossche

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this!
Added a few comments

.. ipython:: python
pd.Timestamp(1349720105, unit='s')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't find it necessary to add an example using Timestamp, IMO we should 'sell' to_datetime as the function to convert things to timestamps. (you can also convert a scalar with to_datetime if you want)

frequency, we can use the pandas functions ``date_range`` and ``bdate_range``
to create timestamp indexes.
frequency, we can use the ``date_range`` and ``bdate_range`` functions
to create a ``DatetimeIndex``. The default frequency for ``date_range`` is a

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make date_range and bdate_range references to their docstring? (:func:`date_range` )

dates outside of those dates if specified.
.. versionadded:: 0.21.0
``bdate_range`` can also generate a range of custom frequency dates by using

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you indent this paragraph, it more 'belongs' to the versionadded directive (although not fully sure how it will look like when rendered)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried indenting and it rendered everything on the same line, i.e. "New in version 0.21.0: bdate_range can also...". I changed it back to make it consistent with the other usages of versionadded within timeseries.rst and other documentation.

@@ -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',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put the weekmask default to None? (as it is only used when freq is something else, so this gives a bit a misleading signature?

And if freq='C' is passed and weekmask is None, you can set it to this value.
(or is None a valid value when freq='C' ?)

@@ -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``,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weekmask -> Weekmask (also the description for 'holidays' can start with capital)

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 '

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this can raise.

@@ -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}')"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bdate_range -> pd.bdate_range (to make it clear that bdate_range is top-level, as opposed to cdate_range)

@jschendel

Made the review changes and fixed some unrelated typos I noticed in whatsnew (missing : and `).

jorisvandenbossche

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

can be represented using a 64-bit integer is limited to approximately 584 years:
.. ipython:: python
pd.Timestamp.min
pd.Timestamp.max
See :ref:`here <timeseries.oob>` for ways to represent data outside these bound.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here the "for ways to represent data outside these bound" is actually useful to know that it is interesting to click this link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, but the 'see also' block will show the full title, which is "representing out of bounds spans", which also says it.

jreback

pd.bdate_range(start, end, freq='CBMS', weekmask=weekmask)
.. warning::

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to the top of the subsection. That way you can in the whatsnew refer directly to this section.

@@ -657,9 +658,9 @@ Numeric
Categorical
^^^^^^^^^^^
- Bug in :func:`Series.isin` when called with a categorical (:issue`16639`)
- Bug in :func:`Series.isin` when called with a categorical (:issue:`16639`)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for fixing this!

@@ -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',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to the deprecated functions section, and add a test (in same module), model after the top-level deprecations.

@@ -3002,5 +3003,3 @@ def generate_range(start=None, end=None, periods=None,
FY5253,
FY5253Quarter,
])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you change this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaning. Seemed a bit strange that Nano was being added to the dict after creation. Looks like it was historically structured that way for compat with numpy < 1.7:

if not _np_version_under1p7:
# Only 1.7+ supports nanosecond resolution
prefix_mapping['N'] = Nano

Structure was kept the same when the if statement was removed, but seems fine to directly add it to the dict during creation now.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k cool

@jschendel

Made the additional review changes.

jreback

def test_deprecation_cdaterange(self):
# GH17596
from pandas.core.indexes.datetimes import cdate_range

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import from pandas here (we are actually testing the pd. deprecation); in this case they are the same, but its our practice to use the one we are deprecating.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we are testing this one (the move to top-level pd namespace was only very recently in master, so we don't have to deprecate that. That one we just removed, and we are deprecating the actual nested one)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, ok then; guess we moved this in 0.21.0, so this is fine then.

jreback

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a minor comment.

@jreback

TomAugspurger

@jreback

ghost pushed a commit to reef-technologies/pandas that referenced this pull request

Oct 2, 2017

alanbato pushed a commit to alanbato/pandas that referenced this pull request

Nov 10, 2017

@jschendel @alanbato

No-Stream pushed a commit to No-Stream/pandas that referenced this pull request

Nov 28, 2017

@jschendel @No-Stream