@@ -144,7 +144,40 @@ def test_numpy_minmax(self):
144
144
tm .assert_raises_regex (
145
145
ValueError , errmsg , np .argmax , dr , out = 0 )
146
146
147
- def test_round (self ):
147
+ @pytest .mark .parametrize ('test_input, rounder, freq, expected' , [
148
+ # GH 14440 & 15578
149
+ ('2016-10-17 12:00:00.0015' , 'round' , 'ms' ,
150
+ '2016-10-17 12:00:00.002000' ),
151
+ ('2016-10-17 12:00:00.0015' , 'round' , 'us' ,
152
+ '2016-10-17 12:00:00.0015' ),
153
+ ('2016-10-17 12:00:00.0015' , 'round' , 'ns' ,
154
+ '2016-10-17 12:00:00.0015' ),
155
+ ('2016-10-17 12:00:00.00149' , 'round' , 'ms' ,
156
+ '2016-10-17 12:00:00.001000' ),
157
+ ('2016-10-17 12:00:00.001501031' , 'round' , '10ns' ,
158
+ '2016-10-17 12:00:00.001501030' ),
159
+ # GH 19206 - times far in the future and past rounding incorrectly
160
+ ('2117-01-01 00:00:45' , 'floor' , '15s' , '2117-01-01 00:00:45' ),
161
+ ('2117-01-01 00:00:45' , 'ceil' , '15s' , '2117-01-01 00:00:45' ),
162
+ ('2117-01-01 00:00:45.000000012' , 'floor' , '10ns' ,
163
+ '2117-01-01 00:00:45.000000010' ),
164
+ ('1823-01-01 00:00:01' , 'floor' , '1s' , '1823-01-01 00:00:01' ),
165
+ ('1823-01-01 00:00:01' , 'ceil' , '1s' , '1823-01-01 00:00:01' ),
166
+ ('1823-01-01 00:00:01.000000012' , 'floor' , '10ns' ,
167
+ '1823-01-01 00:00:01.000000010' ),
168
+ ('1823-01-01 00:00:01.000000012' , 'ceil' , '10ns' ,
169
+ '1823-01-01 00:00:01.000000020' )
170
+ ])
171
+ # @pytest.mark.parametrize('tz', tz)
172
+ def test_round_ops (self , test_input , rounder , freq , expected ):
173
+ for tz in self .tz :
174
+ index = pd .DatetimeIndex ([test_input ], tz = tz )
175
+ func = getattr (index , rounder )
176
+ result = func (freq )
177
+ expect = pd .DatetimeIndex ([expected ], tz = tz )
178
+ tm .assert_index_equal (result , expect )
179
+
180
+ def test_round_raises (self ):
148
181
for tz in self .tz :
149
182
rng = pd .date_range (start = '2016-01-01' , periods = 5 ,
150
183
freq = '30Min' , tz = tz )
@@ -172,25 +205,6 @@ def test_round(self):
172
205
tm .assert_raises_regex (ValueError , msg , rng .round , freq = 'M' )
173
206
tm .assert_raises_regex (ValueError , msg , elt .round , freq = 'M' )
174
207
175
- # GH 14440 & 15578
176
- index = pd .DatetimeIndex (['2016-10-17 12:00:00.0015' ], tz = tz )
177
- result = index .round ('ms' )
178
- expected = pd .DatetimeIndex (['2016-10-17 12:00:00.002000' ], tz = tz )
179
- tm .assert_index_equal (result , expected )
180
-
181
- for freq in ['us' , 'ns' ]:
182
- tm .assert_index_equal (index , index .round (freq ))
183
-
184
- index = pd .DatetimeIndex (['2016-10-17 12:00:00.00149' ], tz = tz )
185
- result = index .round ('ms' )
186
- expected = pd .DatetimeIndex (['2016-10-17 12:00:00.001000' ], tz = tz )
187
- tm .assert_index_equal (result , expected )
188
-
189
- index = pd .DatetimeIndex (['2016-10-17 12:00:00.001501031' ])
190
- result = index .round ('10ns' )
191
- expected = pd .DatetimeIndex (['2016-10-17 12:00:00.001501030' ])
192
- tm .assert_index_equal (result , expected )
193
-
194
208
with tm .assert_produces_warning ():
195
209
ts = '2016-10-17 12:00:00.001501031'
196
210
pd .DatetimeIndex ([ts ]).round ('1010ns' )
0 commit comments