@@ -284,6 +284,14 @@ def test_constructor_dict(self):
284
284
expected = Series ([1 , 2 , nan , 0 ], index = ['b' , 'c' , 'd' , 'a' ])
285
285
assert_series_equal (result , expected )
286
286
287
+ pidx = tm .makePeriodIndex (100 )
288
+ d = {pidx [0 ] : 0 , pidx [1 ] : 1 }
289
+ result = Series (d , index = pidx )
290
+ expected = Series (np .nan , pidx )
291
+ expected .ix [0 ] = 0
292
+ expected .ix [1 ] = 1
293
+ assert_series_equal (result , expected )
294
+
287
295
def test_constructor_subclass_dict (self ):
288
296
data = tm .TestSubDict ((x , 10.0 * x ) for x in xrange (10 ))
289
297
series = Series (data )
@@ -929,6 +937,12 @@ def test_timeseries_repr_object_dtype(self):
929
937
ts = Series (np .random .randn (len (index )), index )
930
938
repr (ts )
931
939
940
+ ts = tm .makeTimeSeries (1000 )
941
+ self .assert_ (repr (ts ).splitlines ()[- 1 ].startswith ('Freq:' ))
942
+
943
+ ts2 = ts .ix [np .random .randint (0 , len (ts )- 1 , 400 )]
944
+ repr (ts ).splitlines ()[- 1 ]
945
+
932
946
def test_iter (self ):
933
947
for i , val in enumerate (self .series ):
934
948
self .assertEqual (val , self .series [i ])
@@ -1202,46 +1216,48 @@ def test_all_any(self):
1202
1216
self .assert_ (bool_series .any ())
1203
1217
1204
1218
def test_operators (self ):
1205
- series = self .ts
1206
- other = self .ts [::2 ]
1207
1219
1208
- def _check_op (other , op , pos_only = False ):
1220
+ def _check_op (series , other , op , pos_only = False ):
1209
1221
left = np .abs (series ) if pos_only else series
1210
1222
right = np .abs (other ) if pos_only else other
1211
1223
1212
1224
cython_or_numpy = op (left , right )
1213
1225
python = left .combine (right , op )
1214
1226
tm .assert_almost_equal (cython_or_numpy , python )
1215
1227
1216
- def check (other ):
1228
+ def check (series , other ):
1217
1229
simple_ops = ['add' , 'sub' , 'mul' , 'truediv' , 'floordiv' ]
1218
1230
1219
1231
for opname in simple_ops :
1220
- _check_op (other , getattr (operator , opname ))
1221
- _check_op (other , operator .pow , pos_only = True )
1222
-
1223
- _check_op (other , lambda x , y : operator .add (y , x ))
1224
- _check_op (other , lambda x , y : operator .sub (y , x ))
1225
- _check_op (other , lambda x , y : operator .truediv (y , x ))
1226
- _check_op (other , lambda x , y : operator .floordiv (y , x ))
1227
- _check_op (other , lambda x , y : operator .mul (y , x ))
1228
- _check_op (other , lambda x , y : operator .pow (y , x ),
1232
+ _check_op (series , other , getattr (operator , opname ))
1233
+
1234
+ _check_op (series , other , operator .pow , pos_only = True )
1235
+
1236
+ _check_op (series , other , lambda x , y : operator .add (y , x ))
1237
+ _check_op (series , other , lambda x , y : operator .sub (y , x ))
1238
+ _check_op (series , other , lambda x , y : operator .truediv (y , x ))
1239
+ _check_op (series , other , lambda x , y : operator .floordiv (y , x ))
1240
+ _check_op (series , other , lambda x , y : operator .mul (y , x ))
1241
+ _check_op (series , other , lambda x , y : operator .pow (y , x ),
1229
1242
pos_only = True )
1230
1243
1231
- check (self .ts * 2 )
1232
- check (self .ts * 0 )
1233
- check (self .ts [::2 ])
1234
- check (5 )
1244
+ check (self .ts , self . ts * 2 )
1245
+ check (self .ts , self . ts * 0 )
1246
+ check (self .ts , self . ts [::2 ])
1247
+ check (self . ts , 5 )
1235
1248
1236
- def check_comparators (other ):
1237
- _check_op (other , operator .gt )
1238
- _check_op (other , operator .ge )
1239
- _check_op (other , operator .eq )
1240
- _check_op (other , operator .lt )
1241
- _check_op (other , operator .le )
1249
+ def check_comparators (series , other ):
1250
+ _check_op (series , other , operator .gt )
1251
+ _check_op (series , other , operator .ge )
1252
+ _check_op (series , other , operator .eq )
1253
+ _check_op (series , other , operator .lt )
1254
+ _check_op (series , other , operator .le )
1255
+
1256
+ check_comparators (self .ts , 5 )
1257
+ check_comparators (self .ts , self .ts + 1 )
1258
+ bool_ser = self .ts > 0
1259
+ check_comparators (bool_ser , bool_ser [::2 ])
1242
1260
1243
- check_comparators (5 )
1244
- check_comparators (self .ts + 1 )
1245
1261
1246
1262
def test_operators_empty_int_corner (self ):
1247
1263
s1 = Series ([], [], dtype = np .int32 )
@@ -1941,6 +1957,13 @@ def test_shift(self):
1941
1957
1942
1958
self .assertRaises (ValueError , ps .shift , freq = 'D' )
1943
1959
1960
+ #legacy support
1961
+ shifted4 = ps .shift (1 , timeRule = 'B' )
1962
+ assert_series_equal (shifted2 , shifted4 )
1963
+
1964
+ shifted5 = ps .shift (1 , offset = datetools .bday )
1965
+ assert_series_equal (shifted5 , shifted4 )
1966
+
1944
1967
def test_tshift (self ):
1945
1968
# PeriodIndex
1946
1969
ps = tm .makePeriodSeries ()
@@ -2050,6 +2073,11 @@ def test_asof(self):
2050
2073
lb = ts .index [14 ]
2051
2074
ub = ts .index [30 ]
2052
2075
2076
+ result = ts .asof (list (dates ))
2077
+ self .assert_ (notnull (result ).all ())
2078
+ lb = ts .index [14 ]
2079
+ ub = ts .index [30 ]
2080
+
2053
2081
mask = (result .index >= lb ) & (result .index < ub )
2054
2082
rs = result [mask ]
2055
2083
self .assert_ ((rs == ts [lb ]).all ())
@@ -2615,6 +2643,10 @@ def test_replace(self):
2615
2643
ser = Series (self .ts .index )
2616
2644
assert_series_equal (ser .replace (np .nan , 0 ), ser .fillna (0 ))
2617
2645
2646
+ # malformed
2647
+ self .assertRaises (ValueError , ser .replace , [1 ,2 ,3 ], [np .nan , 0 ])
2648
+ self .assertRaises (ValueError , ser .replace , xrange (1 ,3 ), [np .nan , 0 ])
2649
+
2618
2650
def test_asfreq (self ):
2619
2651
ts = Series ([0. , 1. , 2. ], index = [datetime (2009 , 10 , 30 ),
2620
2652
datetime (2009 , 11 , 30 ),
0 commit comments