@@ -1155,12 +1155,27 @@ def setUp(self):
11551155 self .rep ['float64' ] = [1.1 , 2.2 ]
11561156 self .rep ['complex128' ] = [1 + 1j , 2 + 2j ]
11571157 self .rep ['bool' ] = [True , False ]
1158+ self .rep ['datetime64[ns]' ] = [pd .Timestamp ('2011-01-01' ),
1159+ pd .Timestamp ('2011-01-03' )]
1160+
1161+ for tz in ['UTC' , 'US/Eastern' ]:
1162+ # to test tz => different tz replacement
1163+ key = 'datetime64[ns, {0}]' .format (tz )
1164+ self .rep [key ] = [pd .Timestamp ('2011-01-01' , tz = tz ),
1165+ pd .Timestamp ('2011-01-03' , tz = tz )]
1166+
1167+ self .rep ['timedelta64[ns]' ] = [pd .Timedelta ('1 day' ),
1168+ pd .Timedelta ('2 day' )]
11581169
11591170 def _assert_replace_conversion (self , from_key , to_key , how ):
11601171 index = pd .Index ([3 , 4 ], name = 'xxx' )
11611172 obj = pd .Series (self .rep [from_key ], index = index , name = 'yyy' )
11621173 self .assertEqual (obj .dtype , from_key )
11631174
1175+ if (from_key .startswith ('datetime' ) and to_key .startswith ('datetime' )):
1176+ # different tz, currently mask_missing raises SystemError
1177+ return
1178+
11641179 if how == 'dict' :
11651180 replacer = dict (zip (self .rep [from_key ], self .rep [to_key ]))
11661181 elif how == 'series' :
@@ -1177,17 +1192,10 @@ def _assert_replace_conversion(self, from_key, to_key, how):
11771192 raise nose .SkipTest ("windows platform buggy: {0} -> {1}" .format
11781193 (from_key , to_key ))
11791194
1180- if ((from_key == 'float64' and
1181- to_key in ('bool' , 'int64' )) or
1182-
1195+ if ((from_key == 'float64' and to_key in ('bool' , 'int64' )) or
11831196 (from_key == 'complex128' and
11841197 to_key in ('bool' , 'int64' , 'float64' )) or
1185-
1186- (from_key == 'int64' and
1187- to_key in ('bool' )) or
1188-
1189- # TODO_GH12747 The result must be int?
1190- (from_key == 'bool' and to_key == 'int64' )):
1198+ (from_key == 'int64' and to_key in ('bool' ))):
11911199
11921200 # buggy on 32-bit
11931201 if tm .is_platform_32bit ():
@@ -1250,13 +1258,31 @@ def test_replace_series_bool(self):
12501258 self ._assert_replace_conversion (from_key , to_key , how = 'series' )
12511259
12521260 def test_replace_series_datetime64 (self ):
1253- pass
1261+ from_key = 'datetime64[ns]'
1262+ for to_key in self .rep :
1263+ self ._assert_replace_conversion (from_key , to_key , how = 'dict' )
1264+
1265+ from_key = 'datetime64[ns]'
1266+ for to_key in self .rep :
1267+ self ._assert_replace_conversion (from_key , to_key , how = 'series' )
12541268
12551269 def test_replace_series_datetime64tz (self ):
1256- pass
1270+ from_key = 'datetime64[ns, US/Eastern]'
1271+ for to_key in self .rep :
1272+ self ._assert_replace_conversion (from_key , to_key , how = 'dict' )
1273+
1274+ from_key = 'datetime64[ns, US/Eastern]'
1275+ for to_key in self .rep :
1276+ self ._assert_replace_conversion (from_key , to_key , how = 'series' )
12571277
12581278 def test_replace_series_timedelta64 (self ):
1259- pass
1279+ from_key = 'timedelta64[ns]'
1280+ for to_key in self .rep :
1281+ self ._assert_replace_conversion (from_key , to_key , how = 'dict' )
1282+
1283+ from_key = 'timedelta64[ns]'
1284+ for to_key in self .rep :
1285+ self ._assert_replace_conversion (from_key , to_key , how = 'series' )
12601286
12611287 def test_replace_series_period (self ):
12621288 pass
0 commit comments