@@ -107,24 +107,25 @@ class TestDatetime(TestCase):
107
107
def test_cf_datetime (self ):
108
108
import netCDF4 as nc4
109
109
for num_dates , units in [
110
- (np .arange (100 ), 'days since 2000-01-01' ),
111
- (np .arange (100 ).reshape (10 , 10 ), 'days since 2000-01-01' ),
112
- (12300 + np .arange (50 ), 'hours since 1680-01-01 00:00:00' ),
110
+ (np .arange (10 ), 'days since 2000-01-01' ),
111
+ (np .arange (10 ).reshape (2 , 5 ), 'days since 2000-01-01' ),
112
+ (12300 + np .arange (5 ), 'hours since 1680-01-01 00:00:00' ),
113
113
# here we add a couple minor formatting errors to test
114
114
# the robustness of the parsing algorithm.
115
- (12300 + np .arange (50 ), 'hour since 1680-01-01 00:00:00' ),
116
- (12300 + np .arange (50 ), u'Hour since 1680-01-01 00:00:00' ),
117
- (12300 + np .arange (50 ), ' Hour since 1680-01-01 00:00:00 ' ),
115
+ (12300 + np .arange (5 ), 'hour since 1680-01-01 00:00:00' ),
116
+ (12300 + np .arange (5 ), u'Hour since 1680-01-01 00:00:00' ),
117
+ (12300 + np .arange (5 ), ' Hour since 1680-01-01 00:00:00 ' ),
118
118
(10 , 'days since 2000-01-01' ),
119
119
([10 ], 'daYs since 2000-01-01' ),
120
120
([[10 ]], 'days since 2000-01-01' ),
121
121
([10 , 10 ], 'days since 2000-01-01' ),
122
122
(0 , 'days since 1000-01-01' ),
123
123
([0 ], 'days since 1000-01-01' ),
124
124
([[0 ]], 'days since 1000-01-01' ),
125
- (np .arange (20 ), 'days since 1000-01-01' ),
126
- (np .arange (0 , 100000 , 10000 ), 'days since 1900-01-01' ),
125
+ (np .arange (2 ), 'days since 1000-01-01' ),
126
+ (np .arange (0 , 100000 , 20000 ), 'days since 1900-01-01' ),
127
127
(17093352.0 , 'hours since 1-1-1 00:00:0.0' ),
128
+ ([0.5 , 1.5 ], 'hours since 1900-01-01T00:00:00' ),
128
129
]:
129
130
for calendar in ['standard' , 'gregorian' , 'proleptic_gregorian' ]:
130
131
expected = _ensure_naive_tz (nc4 .num2date (num_dates , units , calendar ))
@@ -152,15 +153,15 @@ def test_cf_datetime(self):
152
153
# units/encoding cannot be preserved in this case:
153
154
# (Pdb) pd.to_datetime('1-1-1 00:00:0.0')
154
155
# Timestamp('2001-01-01 00:00:00')
155
- self .assertArrayEqual (num_dates , np .around (encoded ))
156
+ self .assertArrayEqual (num_dates , np .around (encoded , 1 ))
156
157
if (hasattr (num_dates , 'ndim' ) and num_dates .ndim == 1
157
158
and '1000' not in units ):
158
159
# verify that wrapping with a pandas.Index works
159
160
# note that it *does not* currently work to even put
160
161
# non-datetime64 compatible dates into a pandas.Index :(
161
162
encoded , _ , _ = conventions .encode_cf_datetime (
162
163
pd .Index (actual ), units , calendar )
163
- self .assertArrayEqual (num_dates , np .around (encoded ))
164
+ self .assertArrayEqual (num_dates , np .around (encoded , 1 ))
164
165
165
166
def test_decoded_cf_datetime_array (self ):
166
167
actual = conventions .DecodedCFDatetimeArray (
@@ -344,7 +345,10 @@ def test_infer_datetime_units(self):
344
345
'1900-01-02 00:00:01' ],
345
346
'seconds since 1900-01-01 00:00:00' ),
346
347
(pd .to_datetime (['1900-01-01' , '1900-01-02' , 'NaT' ]),
347
- 'days since 1900-01-01 00:00:00' )]:
348
+ 'days since 1900-01-01 00:00:00' ),
349
+ (pd .to_datetime (['1900-01-01' ,
350
+ '1900-01-02T00:00:00.005' ]),
351
+ 'seconds since 1900-01-01 00:00:00' )]:
348
352
self .assertEqual (expected , conventions .infer_datetime_units (dates ))
349
353
350
354
def test_infer_timedelta_units (self ):
0 commit comments