@@ -170,23 +170,39 @@ def test_round(self):
170
170
tm .assertRaisesRegexp (ValueError , msg , rng .round , freq = 'M' )
171
171
tm .assertRaisesRegexp (ValueError , msg , elt .round , freq = 'M' )
172
172
173
- def test_repeat (self ):
174
- reps = 2
175
-
176
- for tz in self .tz :
177
- rng = pd .date_range (start = '2016-01-01' , periods = 2 ,
178
- freq = '30Min' , tz = tz )
173
+ def test_repeat_range (self ):
174
+ rng = date_range ('1/1/2000' , '1/1/2001' )
179
175
180
- expected_rng = DatetimeIndex ([
181
- Timestamp ('2016-01-01 00:00:00' , tz = tz , freq = '30T' ),
182
- Timestamp ('2016-01-01 00:00:00' , tz = tz , freq = '30T' ),
183
- Timestamp ('2016-01-01 00:30:00' , tz = tz , freq = '30T' ),
184
- Timestamp ('2016-01-01 00:30:00' , tz = tz , freq = '30T' ),
185
- ])
176
+ result = rng .repeat (5 )
177
+ self .assertIsNone (result .freq )
178
+ self .assertEqual (len (result ), 5 * len (rng ))
186
179
187
- tm .assert_index_equal (rng .repeat (reps ), expected_rng )
180
+ for tz in self .tz :
181
+ index = pd .date_range ('2001-01-01' , periods = 2 , freq = 'D' , tz = tz )
182
+ exp = pd .DatetimeIndex (['2001-01-01' , '2001-01-01' ,
183
+ '2001-01-02' , '2001-01-02' ], tz = tz )
184
+ for res in [index .repeat (2 ), np .repeat (index , 2 )]:
185
+ tm .assert_index_equal (res , exp )
186
+ self .assertIsNone (res .freq )
187
+
188
+ index = pd .date_range ('2001-01-01' , periods = 2 , freq = '2D' , tz = tz )
189
+ exp = pd .DatetimeIndex (['2001-01-01' , '2001-01-01' ,
190
+ '2001-01-03' , '2001-01-03' ], tz = tz )
191
+ for res in [index .repeat (2 ), np .repeat (index , 2 )]:
192
+ tm .assert_index_equal (res , exp )
193
+ self .assertIsNone (res .freq )
194
+
195
+ index = pd .DatetimeIndex (['2001-01-01' , 'NaT' , '2003-01-01' ],
196
+ tz = tz )
197
+ exp = pd .DatetimeIndex (['2001-01-01' , '2001-01-01' , '2001-01-01' ,
198
+ 'NaT' , 'NaT' , 'NaT' ,
199
+ '2003-01-01' , '2003-01-01' , '2003-01-01' ],
200
+ tz = tz )
201
+ for res in [index .repeat (3 ), np .repeat (index , 3 )]:
202
+ tm .assert_index_equal (res , exp )
203
+ self .assertIsNone (res .freq )
188
204
189
- def test_numpy_repeat (self ):
205
+ def test_repeat (self ):
190
206
reps = 2
191
207
msg = "the 'axis' parameter is not supported"
192
208
@@ -201,6 +217,10 @@ def test_numpy_repeat(self):
201
217
Timestamp ('2016-01-01 00:30:00' , tz = tz , freq = '30T' ),
202
218
])
203
219
220
+ res = rng .repeat (reps )
221
+ tm .assert_index_equal (res , expected_rng )
222
+ self .assertIsNone (res .freq )
223
+
204
224
tm .assert_index_equal (np .repeat (rng , reps ), expected_rng )
205
225
tm .assertRaisesRegexp (ValueError , msg , np .repeat ,
206
226
rng , reps , axis = 1 )
@@ -1605,6 +1625,21 @@ def test_shift(self):
1605
1625
name = 'xxx' )
1606
1626
tm .assert_index_equal (idx .shift (- 3 , freq = 'T' ), exp )
1607
1627
1628
+ def test_repeat (self ):
1629
+ index = pd .timedelta_range ('1 days' , periods = 2 , freq = 'D' )
1630
+ exp = pd .TimedeltaIndex (['1 days' , '1 days' , '2 days' , '2 days' ])
1631
+ for res in [index .repeat (2 ), np .repeat (index , 2 )]:
1632
+ tm .assert_index_equal (res , exp )
1633
+ self .assertIsNone (res .freq )
1634
+
1635
+ index = TimedeltaIndex (['1 days' , 'NaT' , '3 days' ])
1636
+ exp = TimedeltaIndex (['1 days' , '1 days' , '1 days' ,
1637
+ 'NaT' , 'NaT' , 'NaT' ,
1638
+ '3 days' , '3 days' , '3 days' ])
1639
+ for res in [index .repeat (3 ), np .repeat (index , 3 )]:
1640
+ tm .assert_index_equal (res , exp )
1641
+ self .assertIsNone (res .freq )
1642
+
1608
1643
1609
1644
class TestPeriodIndexOps (Ops ):
1610
1645
def setUp (self ):
@@ -2526,6 +2561,26 @@ def test_shift(self):
2526
2561
'2011-01-01 09:00' ], name = 'xxx' , freq = 'H' )
2527
2562
tm .assert_index_equal (idx .shift (- 3 ), exp )
2528
2563
2564
+ def test_repeat (self ):
2565
+ index = pd .period_range ('2001-01-01' , periods = 2 , freq = 'D' )
2566
+ exp = pd .PeriodIndex (['2001-01-01' , '2001-01-01' ,
2567
+ '2001-01-02' , '2001-01-02' ], freq = 'D' )
2568
+ for res in [index .repeat (2 ), np .repeat (index , 2 )]:
2569
+ tm .assert_index_equal (res , exp )
2570
+
2571
+ index = pd .period_range ('2001-01-01' , periods = 2 , freq = '2D' )
2572
+ exp = pd .PeriodIndex (['2001-01-01' , '2001-01-01' ,
2573
+ '2001-01-03' , '2001-01-03' ], freq = '2D' )
2574
+ for res in [index .repeat (2 ), np .repeat (index , 2 )]:
2575
+ tm .assert_index_equal (res , exp )
2576
+
2577
+ index = pd .PeriodIndex (['2001-01' , 'NaT' , '2003-01' ], freq = 'M' )
2578
+ exp = pd .PeriodIndex (['2001-01' , '2001-01' , '2001-01' ,
2579
+ 'NaT' , 'NaT' , 'NaT' ,
2580
+ '2003-01' , '2003-01' , '2003-01' ], freq = 'M' )
2581
+ for res in [index .repeat (3 ), np .repeat (index , 3 )]:
2582
+ tm .assert_index_equal (res , exp )
2583
+
2529
2584
2530
2585
if __name__ == '__main__' :
2531
2586
import nose
0 commit comments