Skip to content

DOC: Add more documentation showcasing CalendarDay #22633

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 and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions doc/source/timeseries.rst
Original file line number Diff line number Diff line change
Expand Up @@ -900,12 +900,31 @@ calendar time arithmetic. :class:`CalendarDay` is useful preserving calendar day
semantics with date times with have day light savings transitions, i.e. :class:`CalendarDay`
will preserve the hour before the day light savings transition.

Addition with :class:`CalendarDay`:

.. ipython:: python

ts = pd.Timestamp('2016-10-30 00:00:00', tz='Europe/Helsinki')
ts + pd.offsets.Day(1)
ts + pd.offsets.CalendarDay(1)

Creating a :func:`date_range`:

.. ipython:: python

start = pd.Timestamp('2016-10-30 00:00:00', tz='Europe/Helsinki')
pd.date_range(start, freq='D', periods=3)
pd.date_range(start, freq='CD', periods=3)

Resampling a timeseries:

.. ipython:: python

idx = pd.date_range("2016-10-30", freq='H', periods=4*24, tz='Europe/Helsinki')
s = pd.Series(range(len(idx)), index=idx)
s.resample('D').count()
s.resample('CD').count()
Copy link
Member

Choose a reason for hiding this comment

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

Is this supposed to work on master? After a clean build locally I get a ValueError: Invalid frequency: CD.

Don't think doctest covers these files; if it does then my mistake but figured it was worth asking

Copy link
Member Author

Choose a reason for hiding this comment

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

This currently works on master:

In [3]: pd.__version__
Out[3]: '0.24.0.dev0+563.g0976e1261'

In [4]:    idx = pd.date_range("2016-10-30", freq='H', periods=4*24, tz='Europe/
   ...: Helsinki')
   ...:    s = pd.Series(range(len(idx)), index=idx)
   ...:    s.resample('D').count()
   ...:    s.resample('CD').count()
   ...:
   ...:
Out[4]:
2016-10-30 00:00:00+03:00    25
2016-10-31 00:00:00+02:00    24
2016-11-01 00:00:00+02:00    24
2016-11-02 00:00:00+02:00    23
Freq: CD, dtype: int64

I am not sure if the doctest uses master or the the latest tagged branch.



Parametric Offsets
~~~~~~~~~~~~~~~~~~
Expand Down
22 changes: 21 additions & 1 deletion doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,34 @@ and respect calendar day arithmetic while :class:`Day` and frequency alias ``'D'
will now respect absolute time (:issue:`22274`, :issue:`20596`, :issue:`16980`, :issue:`8774`)
See the :ref:`documentation here <timeseries.dayvscalendarday>` for more information.

Addition with :class:`CalendarDay` across a daylight savings time transition:
The difference between :class:`Day` vs :class:`CalendarDay` is most apparent
with timezone-aware datetime data with a daylight savings time transition:
Copy link
Member

Choose a reason for hiding this comment

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

You say "most apparent with timezone-aware data". But is there a case where this is actually relevant for tz naive data?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no difference between Day and CalendarDay for tz naive data. I've parameterized some tz naive data tests for 'D' and 'CD' to ensure this behavior.


Addition with :class:`CalendarDay`:

.. ipython:: python

ts = pd.Timestamp('2016-10-30 00:00:00', tz='Europe/Helsinki')
ts + pd.offsets.Day(1)
ts + pd.offsets.CalendarDay(1)

Creating a :func:`date_range`:

.. ipython:: python

start = pd.Timestamp('2016-10-30 00:00:00', tz='Europe/Helsinki')
pd.date_range(start, freq='D', periods=3)
pd.date_range(start, freq='CD', periods=3)

Resampling a timeseries:

.. ipython:: python

idx = pd.date_range("2016-10-30", freq='H', periods=4*24, tz='Europe/Helsinki')
s = pd.Series(range(len(idx)), index=idx)
s.resample('D').count()
s.resample('CD').count()

.. _whatsnew_0240.api_breaking.period_end_time:

Time values in ``dt.end_time`` and ``to_timestamp(how='end')``
Expand Down