Skip to content

Commit 2718984

Browse files
chncyhnTomAugspurger
authored andcommitted
DOC: Update the pandas.Series.dt.round/floor/ceil docstrings (#20187)
* DOC: Update the pandas.Series.dt.round/floor/ceil docstrings * DOC: review points fixed. * Add series
1 parent 0d86742 commit 2718984

File tree

1 file changed

+70
-7
lines changed

1 file changed

+70
-7
lines changed

pandas/core/indexes/datetimelike.py

+70-7
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,84 @@ class TimelikeOps(object):
8282

8383
_round_doc = (
8484
"""
85-
%s the index to the specified freq
85+
{op} the data to the specified `freq`.
8686
8787
Parameters
8888
----------
89-
freq : freq string/object
89+
freq : str or Offset
90+
The frequency level to {op} the index to. Must be a fixed
91+
frequency like 'S' (second) not 'ME' (month end). See
92+
:ref:`frequency aliases <timeseries.offset_aliases>` for
93+
a list of possible `freq` values.
9094
9195
Returns
9296
-------
93-
index of same type
97+
DatetimeIndex, TimedeltaIndex, or Series
98+
Index of the same type for a DatetimeIndex or TimedeltaIndex,
99+
or a Series with the same index for a Series.
94100
95101
Raises
96102
------
97-
ValueError if the freq cannot be converted
103+
ValueError if the `freq` cannot be converted.
104+
105+
Examples
106+
--------
107+
**DatetimeIndex**
108+
109+
>>> rng = pd.date_range('1/1/2018 11:59:00', periods=3, freq='min')
110+
>>> rng
111+
DatetimeIndex(['2018-01-01 11:59:00', '2018-01-01 12:00:00',
112+
'2018-01-01 12:01:00'],
113+
dtype='datetime64[ns]', freq='T')
114+
""")
115+
116+
_round_example = (
117+
""">>> rng.round('H')
118+
DatetimeIndex(['2018-01-01 12:00:00', '2018-01-01 12:00:00',
119+
'2018-01-01 12:00:00'],
120+
dtype='datetime64[ns]', freq=None)
121+
122+
**Series**
123+
124+
>>> pd.Series(rng).dt.round("H")
125+
0 2018-01-01 12:00:00
126+
1 2018-01-01 12:00:00
127+
2 2018-01-01 12:00:00
128+
dtype: datetime64[ns]
98129
""")
99130

131+
_floor_example = (
132+
""">>> rng.floor('H')
133+
DatetimeIndex(['2018-01-01 11:00:00', '2018-01-01 12:00:00',
134+
'2018-01-01 12:00:00'],
135+
dtype='datetime64[ns]', freq=None)
136+
137+
**Series**
138+
139+
>>> pd.Series(rng).dt.floor("H")
140+
0 2018-01-01 11:00:00
141+
1 2018-01-01 12:00:00
142+
2 2018-01-01 12:00:00
143+
dtype: datetime64[ns]
144+
"""
145+
)
146+
147+
_ceil_example = (
148+
""">>> rng.ceil('H')
149+
DatetimeIndex(['2018-01-01 12:00:00', '2018-01-01 12:00:00',
150+
'2018-01-01 13:00:00'],
151+
dtype='datetime64[ns]', freq=None)
152+
153+
**Series**
154+
155+
>>> pd.Series(rng).dt.ceil("H")
156+
0 2018-01-01 12:00:00
157+
1 2018-01-01 12:00:00
158+
2 2018-01-01 13:00:00
159+
dtype: datetime64[ns]
160+
"""
161+
)
162+
100163
def _round(self, freq, rounder):
101164
# round the local times
102165
values = _ensure_datetimelike_to_i8(self)
@@ -111,15 +174,15 @@ def _round(self, freq, rounder):
111174
return self._ensure_localized(
112175
self._shallow_copy(result, **attribs))
113176

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

118-
@Appender(_round_doc % "floor")
181+
@Appender((_round_doc + _floor_example).format(op="floor"))
119182
def floor(self, freq):
120183
return self._round(freq, np.floor)
121184

122-
@Appender(_round_doc % "ceil")
185+
@Appender((_round_doc + _ceil_example).format(op="ceil"))
123186
def ceil(self, freq):
124187
return self._round(freq, np.ceil)
125188

0 commit comments

Comments
 (0)