@@ -2128,9 +2128,9 @@ def test_constructor_dtype_timedelta64(self):
2128
2128
for i in range (3 )] + [np .nan ], dtype = 'm8[ns]' )
2129
2129
self .assert_ (td .dtype == 'timedelta64[ns]' )
2130
2130
2131
- # invalid astypes
2132
- for t in ['s' , 'D' , 'us' , 'ms' ]:
2133
- self .assertRaises (TypeError , td .astype , 'm8[%s]' % t )
2131
+ # these are frequency conversion astypes
2132
+ # for t in ['s', 'D', 'us', 'ms']:
2133
+ # self.assertRaises(TypeError, td.astype, 'm8[%s]' % t)
2134
2134
2135
2135
# valid astype
2136
2136
td .astype ('int64' )
@@ -2371,10 +2371,18 @@ def test_timedelta64_conversions(self):
2371
2371
2372
2372
for m in [1 , 3 , 10 ]:
2373
2373
for unit in ['D' ,'h' ,'m' ,'s' ,'ms' ,'us' ,'ns' ]:
2374
+
2375
+ # op
2374
2376
expected = s1 .apply (lambda x : x / np .timedelta64 (m ,unit ))
2375
2377
result = s1 / np .timedelta64 (m ,unit )
2376
2378
assert_series_equal (result , expected )
2377
2379
2380
+ if m == 1 and unit != 'ns' :
2381
+
2382
+ # astype
2383
+ result = s1 .astype ("timedelta64[{0}]" .format (unit ))
2384
+ assert_series_equal (result , expected )
2385
+
2378
2386
# reverse op
2379
2387
expected = s1 .apply (lambda x : np .timedelta64 (m ,unit ) / x )
2380
2388
result = np .timedelta64 (m ,unit ) / s1
0 commit comments