@@ -82,21 +82,84 @@ class TimelikeOps(object):
82
82
83
83
_round_doc = (
84
84
"""
85
- %s the index to the specified freq
85
+ {op} the data to the specified ` freq`.
86
86
87
87
Parameters
88
88
----------
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.
90
94
91
95
Returns
92
96
-------
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.
94
100
95
101
Raises
96
102
------
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]
98
129
""" )
99
130
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
+
100
163
def _round (self , freq , rounder ):
101
164
# round the local times
102
165
values = _ensure_datetimelike_to_i8 (self )
@@ -111,15 +174,15 @@ def _round(self, freq, rounder):
111
174
return self ._ensure_localized (
112
175
self ._shallow_copy (result , ** attribs ))
113
176
114
- @Appender (_round_doc % "round" )
177
+ @Appender (( _round_doc + _round_example ). format ( op = "round" ) )
115
178
def round (self , freq , * args , ** kwargs ):
116
179
return self ._round (freq , np .round )
117
180
118
- @Appender (_round_doc % "floor" )
181
+ @Appender (( _round_doc + _floor_example ). format ( op = "floor" ) )
119
182
def floor (self , freq ):
120
183
return self ._round (freq , np .floor )
121
184
122
- @Appender (_round_doc % "ceil" )
185
+ @Appender (( _round_doc + _ceil_example ). format ( op = "ceil" ) )
123
186
def ceil (self , freq ):
124
187
return self ._round (freq , np .ceil )
125
188
0 commit comments