10000
1
1
from __future__ import division , absolute_import , print_function
2
2
3
- import os , pickle
3
+ import pickle
4
+
4
5
import numpy
5
6
import numpy as np
6
- from numpy .testing import *
7
- from numpy .compat import asbytes
8
7
import datetime
8
+ from numpy .compat import asbytes
9
+ from numpy .testing import (
10
+ TestCase , run_module_suite , assert_ , assert_equal , assert_raises ,
11
+ dec
12
+ )
9
13
10
14
# Use pytz to test out various time zones if available
11
15
try :
@@ -20,7 +24,7 @@ def test_datetime_dtype_creation(self):
20
24
for unit in ['Y' , 'M' , 'W' , 'D' ,
21
25
'h' , 'm' , 's' , 'ms' , 'us' ,
22
26
'ns' , 'ps' , 'fs' , 'as' ]:
23
- dt1 = np .dtype ('M8[750%s]' % unit )
27
+ dt1 = np .dtype ('M8[750%s]' % unit )
24
28
assert_ (dt1 == np .dtype ('datetime64[750%s]' % unit ))
25
29
dt2 = np .dtype ('m8[%s]' % unit )
26
30
assert_ (dt2 == np .dtype ('timedelta64[%s]' % unit ))
@@ -522,7 +526,7 @@ def test_datetime_array_str(self):
522
526
523
527
a = np .array (['2011-03-16T13:55Z' , '1920-01-01T03:12Z' ], dtype = 'M' )
524
528
assert_equal (np .array2string (a , separator = ', ' ,
525
- formatter = {'datetime' : lambda x :
529
+ formatter = {'datetime' : lambda x :
526
530
"'%s'" % np .datetime_as_string (x , timezone = 'UTC' )}),
527
531
"['2011-03-16T13:55Z', '1920-01-01T03:12Z']" )
528
532
@@ -608,11 +612,11 @@ def test_cast_overflow(self):
608
612
def cast ():
609
613
numpy .datetime64 ("1971-01-01 00:00:00.000000000000000" ).astype ("<M8[D]" )
610
614
assert_raises (OverflowError , cast )
615
+
611
616
def cast2 ():
612
617
numpy .datetime64 ("2014" ).astype ("<M8[fs]" )
613
618
assert_raises (OverflowError , cast2 )
614
619
615
-
616
620
def test_pyobject_roundtrip (self ):
617
621
# All datetime types should be able to roundtrip through object
618
622
a = np .array ([0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
@@ -1080,7 +1084,7 @@ def test_datetime_minmax(self):
1080
1084
def test_hours (self ):
1081
1085
t = np .ones (3 , dtype = 'M8[s]' )
1082
1086
t [0 ] = 60 * 60 * 24 + 60 * 60 * 10
1083
- assert_ (t [0 ].item ().hour == 10 )
1087
+ assert_ (t [0 ].item ().hour == 10 )
1084
1088
1085
1089
def test_divisor_conversion_year (self ):
1086
1090
assert_ (np .dtype ('M8[Y/4]' ) == np .dtype ('M8[3M]' ))
@@ -1116,10 +1120,10 @@ def test_divisor_conversion_second(self):
1116
1120
1117
1121
def test_divisor_conversion_fs (self ):
1118
1122
assert_ (np .dtype ('M8[fs/100]' ) == np .dtype ('M8[10as]' ))
1119
- self .assertRaises (ValueError , lambda : np .dtype ('M8[3fs/10000]' ))
1123
+ self .assertRaises (ValueError , lambda : np .dtype ('M8[3fs/10000]' ))
1120
1124
1121
1125
def test_divisor_conversion_as (self ):
1122
- self .assertRaises (ValueError , lambda : np .dtype ('M8[as/10]' ))
1126
+ self .assertRaises (ValueError , lambda : np .dtype ('M8[as/10]' ))
1123
1127
1124
1128
def test_string_parser_variants (self ):
1125
1129
# Allow space instead of 'T' between date and time
@@ -1141,7 +1145,6 @@ def test_string_parser_variants(self):
1141
1145
assert_equal (np .datetime64 ('1977-03-02T12:30-0230' ),
1142
1146
np .datetime64 ('1977-03-02T15:00Z' ))
1143
1147
1144
-
1145
1148
def test_string_parser_error_check (self ):
1146
1149
# Arbitrary bad string
1147
1150
assert_raises (ValueError , np .array , ['badvalue' ], np .dtype ('M8[us]' ))
@@ -1220,7 +1223,6 @@ def test_string_parser_error_check(self):
1220
1223
assert_raises (ValueError , np .array , ['1980-02-03 01:01:00-25:00' ],
1221
1224
np .dtype ('M8[us]' ))
1222
1225
1223
-
1224
1226
def test_creation_overflow (self ):
1225
1227
date = '1980-03-23 20:00:00Z'
1226
1228
timesteps = np .array ([date ], dtype = 'datetime64[s]' )[0 ].astype (np .int64 )
@@ -1312,39 +1314,31 @@ def test_datetime_as_string(self):
1312
1314
1313
1315
# unit='auto' parameter
1314
1316
assert_equal (np .datetime_as_string (
1315
- np .datetime64 ('2032-07-18T12:23:34.123456Z' , 'us' ),
1316
- unit = 'auto' ),
1317
- '2032-07-18T12:23:34.123456Z' )
1317
+ np .datetime64 ('2032-07-18T12:23:34.123456Z' , 'us' ), unit = 'auto' ),
1318
+ '2032-07-18T12:23:34.123456Z' )
1318
1319
assert_equal (np .datetime_as_string (
1319
- np .datetime64 ('2032-07-18T12:23:34.12Z' , 'us' ),
1320
- unit = 'auto' ),
1321
- '2032-07-18T12:23:34.120Z' )
1320
+ np .datetime64 ('2032-07-18T12:23:34.12Z' , 'us' ), unit = 'auto' ),
1321
+ '2032-07-18T12:23:34.120Z' )
1322
1322
assert_equal (np .datetime_as_string (
1323
- np .datetime64 ('2032-07-18T12:23:34Z' , 'us' ),
1324
- unit = 'auto' ),
1325
- '2032-07-18T12:23:34Z' )
1323
+ np .datetime64 ('2032-07-18T12:23:34Z' , 'us' ), unit = 'auto' ),
1324
+ '2032-07-18T12:23:34Z' )
1326
1325
assert_equal (np .datetime_as_string (
1327
- np .datetime64 ('2032-07-18T12:23:00Z' , 'us' ),
1328
- unit = 'auto' ),
1329
- '2032-07-18T12:23Z' )
1326
+ np .datetime64 ('2032-07-18T12:23:00Z' , 'us' ), unit = 'auto' ),
1327
+ '2032-07-18T12:23Z' )
1330
1328
# 'auto' doesn't split up hour and minute
1331
1329
assert_equal (np .datetime_as_string (
1332
- np .datetime64 ('2032-07-18T12:00:00Z' , 'us' ),
1333
- unit = 'auto' ),
1334
- '2032-07-18T12:00Z' )
1330
+ np .datetime64 ('2032-07-18T12:00:00Z' , 'us' ), unit = 'auto' ),
1331
+ '2032-07-18T12:00Z' )
1335
1332
assert_equal (np .datetime_as_string (
1336
- np .datetime64 ('2032-07-18T00:00:00Z' , 'us' ),
1337
- unit = 'auto' ),
1338
- '2032-07-18' )
1333
+ np .datetime64 ('2032-07-18T00:00:00Z' , 'us' ), unit = 'auto' ),
1334
+ '2032-07-18' )
1339
1335
# 'auto' doesn't split up the date
1340
1336
assert_equal (np .datetime_as_string (
1341
- np .datetime64 ('2032-07-01T00:00:00Z' , 'us' ),
1342
- unit = 'auto' ),
1343
- '2032-07-01' )
1337
+ np .datetime64 ('2032-07-01T00:00:00Z' , 'us' ), unit = 'auto' ),
1338
+ '2032-07-01' )
1344
1339
assert_equal (np .datetime_as_string (
1345
- np .datetime64 ('2032-01-01T00:00:00Z' , 'us' ),
1346
- unit = 'auto' ),
1347
- '2032-01-01' )
1340
+ np .datetime64 ('2032-01-01T00:00:00Z' , 'us' ), unit = 'auto' ),
1341
+ '2032-01-01' )
1348
1342
1349
1343
@dec .skipif (not _has_pytz , "The pytz module is not available." )
1350
1344
def test_datetime_as_string_timezone (self ):
@@ -1610,7 +1604,7 @@ def test_datetime_busday_holidays_offset(self):
1610
1604
np .datetime64 ('2011-11-10' ))
1611
1605
1612
1606
# A bigger forward jump across more than one week/holiday
1613
- holidays = ['2011-10-10' , '2011-11-11' , '2011-11-24' ,
1607
+ holidays = ['2011-10-10' , '2011-11-11' , '2011-11-24' ,
1614
1608
'2011-12-25' , '2011-05-30' , '2011-02-21' ,
1615
1609
'2011-12-26' , '2012-01-02' ]
1616
1610
bdd = np .busdaycalendar (weekmask = '1111100' , holidays = holidays )
@@ -1712,10 +1706,10 @@ def test_datetime_busday_holidays_offset(self):
1712
1706
np .datetime64 ('2012-03-08' ))
1713
1707
1714
1708
def test_datetime_busday_holidays_count (self ):
1715
- holidays = ['2011-01-01' , '2011-10-10' , '2011-11-11' , '2011-11-24' ,
1716
- '2011-12-25' , '2011-05-30' , '2011-02-21' , '2011-01-17' ,
1717
- '2011-12-26' , '2012-01-02' , '2011-02-21' , '2011-05-30' ,
1718
- '2011-07-01' , '2011-07-04' , '2011-09-05' , '2011-10-10' ]
1709
+ holidays = ['2011-01-01' , '2011-10-10' , '2011-11-11' , '2011-11-24' ,
1710
+ '2011-12-25' , '2011-05-30' , '2011-02-21' , '2011-01-17' ,
1711
+ '2011-12-26' , '2012-01-02' , '2011-02-21' , '2011-05-30' ,
1712
+ '2011-07-01' , '2011-07-04' , '2011-09-05' , '2011-10-10' ]
1719
1713
bdd = np .busdaycalendar (weekmask = '1111100' , holidays = holidays )
1720
1714
1721
1715
# Validate against busday_offset broadcast against
@@ -1748,11 +1742,11 @@ def test_datetime_busday_holidays_count(self):
1748
1742
assert_equal (np .busday_count ('2011-04' , '2011-03' , weekmask = 'Mon' ), - 4 )
1749
1743
1750
1744
def test_datetime_is_busday (self ):
1751
- holidays = ['2011-01-01' , '2011-10-10' , '2011-11-11' , '2011-11-24' ,
1752
- '2011-12-25' , '2011-05-30' , '2011-02-21' , '2011-01-17' ,
1753
- '2011-12-26' , '2012-01-02' , '2011-02-21' , '2011-05-30' ,
1754
- '2011-07-01' , '2011-07-04' , '2011-09-05' , '2011-10-10' ,
1755
- 'NaT' ]
1745
+ holidays = ['2011-01-01' , '2011-10-10' , '2011-11-11' , '2011-11-24' ,
1746
+ '2011-12-25' , '2011-05-30' , '2011-02-21' , '2011-01-17' ,
1747
+ '2011-12-26' , '2012-01-02' , '2011-02-21' , '2011-05-30' ,
1748
+ '2011-07-01' , '2011-07-04' , '2011-09-05' , '2011-10-10' ,
1749
+ 'NaT' ]
1756
1750
bdd = np .busdaycalendar (weekmask = '1111100' , holidays = holidays )
1757
1751
1758
1752
# Weekend/weekday tests
0 commit comments