-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Update DateOffset intro in timeseries.rst #23385
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
Conversation
@datapythonista if you could have a look |
Codecov Report
@@ Coverage Diff @@
## master #23385 +/- ##
=======================================
Coverage 92.24% 92.24%
=======================================
Files 161 161
Lines 51318 51318
=======================================
Hits 47339 47339
Misses 3979 3979
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, added some comments.
It's probably worth that @jbrockmendel takes a look too.
doc/source/timeseries.rst
Outdated
@@ -8,6 +8,7 @@ | |||
import numpy as np | |||
import pandas as pd | |||
from pandas import offsets | |||
from pandas.tseries.offsets import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd avoid importing star even in the documentation.
doc/source/timeseries.rst
Outdated
:class:`Series` and :class:`DataFrame` have extended data type support and functionality for ``datetime`` and ``timedelta`` | ||
data when the time data is used as data itself. The ``Period`` and ``DateOffset`` data will be stored as ``object`` data. | ||
:class:`Series` and :class:`DataFrame` have extended data type support and functionality for ``datetime``, ``timedelta`` | ||
and ``Period`` data when the time data is used as data itself. The ``DateOffset`` data will be stored as ``object`` data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the "when the time data is used as data itself" not very clear
Subclasses of ``DateOffset`` define the ``apply`` function which dictates | ||
custom date increment logic, such as adding business days: | ||
These frequency strings map to a :class:`DateOffset` object and its subclasses. A :class:`DateOffset` | ||
is similar to a :class:`Timedelta` that represents a duration of time but follows specific calendar duration rules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think an example (explaining, not code) would be helpful here. What calendar duration rules means can not be so obvious. Just saying that in one case we are adding 24 hours, and in the other we are going to the same time of the next day, even if that can be 23 or 25 hours, would make this much clearer I think.
doc/source/timeseries.rst
Outdated
@@ -968,6 +964,7 @@ particular day of the week: | |||
|
|||
.. ipython:: python | |||
|
|||
d = datetime(2008, 8, 18, 9, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer to import datetime
, and then use datetime.datetime(...)
. I think it's more explicit, and better to import modules directly.
doc/source/timeseries.rst
Outdated
"""DateOffset increments between business days""" | ||
def apply(self, other): | ||
... | ||
The basic :class:`DateOffset` acts similar to ``dateutil.relativedelta`` that shifts a date time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a link to dateutil docs for this
It's definitely worth exploring the ``pandas.tseries.offsets`` module and the | ||
various docstrings for the classes. | ||
# This particular day contains a day light savings time transition | ||
ts = pd.Timestamp('2016-10-30 00:00:00', tz='Europe/Helsinki') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put this section on DST a bit lower, as you really should explain DateOffsets first
Updated based on the review. Also change the page's |
:class:`Series` and :class:`DataFrame` have extended data type support and functionality for ``datetime`` and ``timedelta`` | ||
data when the time data is used as data itself. The ``Period`` and ``DateOffset`` data will be stored as ``object`` data. | ||
:class:`Series` and :class:`DataFrame` have extended data type support and functionality for ``datetime``, ``timedelta`` | ||
and ``Period`` data when passed into those constructors. ``DateOffset`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May need to be careful about this, as Period only supports a subset of DateOffsets, which has caused confusion in the past.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know. This section is more describing what dtypes are supported by Series and DataFrames (i.e. Period dtype is supported but not DateOffset (since it doesnt really have its own data type))
can you post a rendering of this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
doc/source/timeseries.rst
Outdated
is similar to a :class:`Timedelta` that represents a duration of time but follows specific calendar duration rules. | ||
For example, a :class:`Timedelta` day will always increment ``datetimes`` by 24 hours, while a :class:`DateOffset` day | ||
will increment ``datetimes`` to the same time the next day whether a day represents 23, 24 or 25 hours due to daylight | ||
savings time. However, the following date offsets behave like :class:`Timedelta` and respect absolute time: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would explain the logic of this list: all offsets of an hour or smaller
(and maybe just put them in running text instead of a list)
lgtm. |
over to you @jorisvandenbossche |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some small comments
# Bring the date to the closest offset date (Monday) | ||
offset.rollforward(ts) | ||
# Date is brought to the closest offset date first and then the hour is added | ||
ts + offset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't directly understand this difference between rollforward and addition based on this example. Would it be worth expanding more on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
.. ipython:: python | ||
|
||
ts = pd.Timestamp('2014-01-01 09:00') | ||
day = Day() | ||
day = pd.offsets.Day() | ||
day.apply(ts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apply
has not yet been explained (it was there before above, but in a part you deleted)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Added this in an earlier section.
increment will be applied multiple times. | ||
* It has :meth:`~pandas.DateOffset.rollforward` and | ||
:meth:`~pandas.DateOffset.rollback` methods for moving a date forward or | ||
backward to the next or previous "offset date". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the feeling this summary list had some value as well. Should we keep it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I demonstrated the first two points in examples above and I think I clarified rollback
and rollforward
a lot better in its own section.
@jorisvandenbossche any additional comments? |
@jorisvandenbossche do you mind checking if your comments have been addressed and this can be merged? We're making other changes to |
I'll push this in tomorrow if there are no other comments. I can always follow up after merging this PR. |
thanks @mroeschke |
Updated
timeseries.rst
introduction to DateOffsetsTimedelta
Misc fixes: