Skip to content
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

DOC: Update the pandas.Series.dt.round/floor/ceil docstrings #20187

Merged
merged 3 commits into from
Mar 11, 2018
Merged
Changes from 1 commit
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
50 changes: 44 additions & 6 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,59 @@ class TimelikeOps(object):

_round_doc = (
"""
%s the index to the specified freq
{op} the index to the specified `freq`.

Parameters
----------
freq : freq string/object
The frequency level to {op} the index to.

Returns
-------
index of same type
index of same type.

Raises
------
ValueError if the freq cannot be converted
ValueError if the `freq` cannot be converted.

Notes
-----
See the following link for possible `freq` values
and their descriptions.\n
https://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use syntax like

See :ref:`frequency aliases <timeseries.offset_aliases>` for a list of possible `freq` values.


Examples
--------
>>> rng = pd.date_range('1/1/2018 11:59:00', periods=3, freq='min')
>>> rng
DatetimeIndex(['2018-01-01 11:59:00', '2018-01-01 12:00:00',
'2018-01-01 12:01:00'],
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be formatted like
>>> rng
DatetimeIndex(['2018-01-01 11:59:00', '2018-01-01 12:00:00',
... '2018-01-01 12:01:00'],
... dtype='datetime64[ns]', freq='T')

so that the doctests pass. (... on continuation lines and line up the values). Same with the rest.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I was wrong about the ..., dont' need that. But the lines should be aligned.

dtype='datetime64[ns]', freq='T')
""")

_round_example = (
""">>> rng.round('H')
DatetimeIndex(['2018-01-01 12:00:00', '2018-01-01 12:00:00',
'2018-01-01 12:00:00'],
dtype='datetime64[ns]', freq=None)
""")

_floor_example = (
""">>> rng.floor('H')
DatetimeIndex(['2018-01-01 11:00:00', '2018-01-01 12:00:00',
'2018-01-01 12:00:00'],
dtype='datetime64[ns]', freq=None)
"""
)

_ceil_example = (
""">>> rng.ceil('H')
DatetimeIndex(['2018-01-01 12:00:00', '2018-01-01 12:00:00',
'2018-01-01 13:00:00'],
dtype='datetime64[ns]', freq=None)
"""
)

def _round(self, freq, rounder):
# round the local times
values = _ensure_datetimelike_to_i8(self)
Expand All @@ -111,15 +149,15 @@ def _round(self, freq, rounder):
return self._ensure_localized(
self._shallow_copy(result, **attribs))

@Appender(_round_doc % "round")
@Appender((_round_doc + _round_example).format(op="round"))
def round(self, freq, *args, **kwargs):
return self._round(freq, np.round)

@Appender(_round_doc % "floor")
@Appender((_round_doc + _floor_example).format(op="floor"))
def floor(self, freq):
return self._round(freq, np.floor)

@Appender(_round_doc % "ceil")
@Appender((_round_doc + _ceil_example).format(op="ceil"))
def ceil(self, freq):
return self._round(freq, np.ceil)

Expand Down