Skip to content

Commit

Permalink
DOC: Update the pandas.Series.dt.round/floor/ceil docstrings (pandas-…
Browse files Browse the repository at this point in the history
…dev#20187)

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

* DOC: review points fixed.

* Add series
  • Loading branch information
chncyhn authored and TomAugspurger committed Mar 11, 2018
1 parent 0d86742 commit 2718984
Showing 1 changed file with 70 additions and 7 deletions.
77 changes: 70 additions & 7 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,84 @@ class TimelikeOps(object):

_round_doc = (
"""
%s the index to the specified freq
{op} the data to the specified `freq`.
Parameters
----------
freq : freq string/object
freq : str or Offset
The frequency level to {op} the index to. Must be a fixed
frequency like 'S' (second) not 'ME' (month end). See
:ref:`frequency aliases <timeseries.offset_aliases>` for
a list of possible `freq` values.
Returns
-------
index of same type
DatetimeIndex, TimedeltaIndex, or Series
Index of the same type for a DatetimeIndex or TimedeltaIndex,
or a Series with the same index for a Series.
Raises
------
ValueError if the freq cannot be converted
ValueError if the `freq` cannot be converted.
Examples
--------
**DatetimeIndex**
>>> 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'],
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)
**Series**
>>> pd.Series(rng).dt.round("H")
0 2018-01-01 12:00:00
1 2018-01-01 12:00:00
2 2018-01-01 12:00:00
dtype: datetime64[ns]
""")

_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)
**Series**
>>> pd.Series(rng).dt.floor("H")
0 2018-01-01 11:00:00
1 2018-01-01 12:00:00
2 2018-01-01 12:00:00
dtype: datetime64[ns]
"""
)

_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)
**Series**
>>> pd.Series(rng).dt.ceil("H")
0 2018-01-01 12:00:00
1 2018-01-01 12:00:00
2 2018-01-01 13:00:00
dtype: datetime64[ns]
"""
)

def _round(self, freq, rounder):
# round the local times
values = _ensure_datetimelike_to_i8(self)
Expand All @@ -111,15 +174,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

0 comments on commit 2718984

Please sign in to comment.