3
3
import sys
4
4
import warnings
5
5
6
+ from nose .tools import assert_raises
6
7
from datetime import datetime
7
8
from numpy .random import randn
8
9
from numpy .testing .decorators import slow
@@ -98,19 +99,6 @@ def tests_skip_nuisance(self):
98
99
result = r .sum ()
99
100
assert_frame_equal (result , expected )
100
101
101
- def test_timedeltas (self ):
102
-
103
- df = DataFrame ({'A' : range (5 ),
104
- 'B' : pd .timedelta_range ('1 day' , periods = 5 )})
105
- r = df .rolling (window = 3 )
106
- result = r .sum ()
107
- expected = DataFrame ({'A' : [np .nan , np .nan , 3 , 6 , 9 ],
108
- 'B' : pd .to_timedelta ([pd .NaT , pd .NaT ,
109
- '6 days' , '9 days' ,
110
- '12 days' ])},
111
- columns = list ('AB' ))
112
- assert_frame_equal (result , expected )
113
-
114
102
def test_agg (self ):
115
103
df = DataFrame ({'A' : range (5 ), 'B' : range (0 , 10 , 2 )})
116
104
@@ -291,8 +279,13 @@ def test_deprecations(self):
291
279
292
280
# GH #12373 : rolling functions error on float32 data
293
281
# make sure rolling functions works for different dtypes
294
- class TestDtype (Base ):
295
- dtype = None
282
+ #
283
+ # NOTE that these are yielded tests and so _create_data is
284
+ # explicity called, nor do these inherit from unittest.TestCase
285
+ #
286
+ # further note that we are only checking rolling for fully dtype
287
+ # compliance (though both expanding and ewm inherit)
288
+ class Dtype (object ):
296
289
window = 2
297
290
298
291
funcs = {
@@ -371,76 +364,84 @@ def _create_dtype_data(self, dtype):
371
364
return data
372
365
373
366
def _create_data (self ):
374
- super (TestDtype , self )._create_data ()
375
367
self .data = self ._create_dtype_data (self .dtype )
376
368
self .expects = self .get_expects ()
377
369
378
- def setUp (self ):
379
- self ._create_data ()
380
-
381
370
def test_dtypes (self ):
371
+ self ._create_data ()
382
372
for f_name , d_name in product (self .funcs .keys (), self .data .keys ()):
383
373
f = self .funcs [f_name ]
384
374
d = self .data [d_name ]
385
- assert_equal = assert_series_equal if isinstance (
386
- d , Series ) else assert_frame_equal
387
375
exp = self .expects [d_name ][f_name ]
376
+ yield self .check_dtypes , f , f_name , d , d_name , exp
388
377
389
- roll = d . rolling ( window = self . window )
390
- result = f ( roll )
391
-
392
- assert_equal (result , exp )
378
+ def check_dtypes ( self , f , f_name , d , d_name , exp ):
379
+ roll = d . rolling ( window = self . window )
380
+ result = f ( roll )
381
+ assert_almost_equal (result , exp )
393
382
394
383
395
- class TestDtype_object (TestDtype ):
384
+ class TestDtype_object (Dtype ):
396
385
dtype = object
397
386
398
387
399
- class TestDtype_int8 (TestDtype ):
388
+ class Dtype_integer (Dtype ):
389
+ pass
390
+
391
+
392
+ class TestDtype_int8 (Dtype_integer ):
400
393
dtype = np .int8
401
394
402
395
403
- class TestDtype_int16 (TestDtype ):
396
+ class TestDtype_int16 (Dtype_integer ):
404
397
dtype = np .int16
405
398
406
399
407
- class TestDtype_int32 (TestDtype ):
400
+ class TestDtype_int32 (Dtype_integer ):
408
401
dtype = np .int32
409
402
410
403
411
- class TestDtype_int64 (TestDtype ):
404
+ class TestDtype_int64 (Dtype_integer ):
412
405
dtype = np .int64
413
406
414
407
415
- class TestDtype_uint8 (TestDtype ):
408
+ class Dtype_uinteger (Dtype ):
409
+ pass
410
+
411
+
412
+ class TestDtype_uint8 (Dtype_uinteger ):
416
413
dtype = np .uint8
417
414
418
415
419
- class TestDtype_uint16 (TestDtype ):
416
+ class TestDtype_uint16 (Dtype_uinteger ):
420
417
dtype = np .uint16
421
418
422
419
423
- class TestDtype_uint32 (TestDtype ):
420
+ class TestDtype_uint32 (Dtype_uinteger ):
424
421
dtype = np .uint32
425
422
426
423
427
- class TestDtype_uint64 (TestDtype ):
424
+ class TestDtype_uint64 (Dtype_uinteger ):
428
425
dtype = np .uint64
429
426
430
427
431
- class TestDtype_float16 (TestDtype ):
428
+ class Dtype_float (Dtype ):
429
+ pass
430
+
431
+
432
+ class TestDtype_float16 (Dtype_float ):
432
433
dtype = np .float16
433
434
434
435
435
- class TestDtype_float32 (TestDtype ):
436
+ class TestDtype_float32 (Dtype_float ):
436
437
dtype = np .float32
437
438
438
439
439
- class TestDtype_float64 (TestDtype ):
440
+ class TestDtype_float64 (Dtype_float ):
440
441
dtype = np .float64
441
442
442
443
443
- class TestDtype_category (TestDtype ):
444
+ class TestDtype_category (Dtype ):
444
445
dtype = 'category'
445
446
include_df = False
446
447
@@ -456,25 +457,37 @@ def _create_dtype_data(self, dtype):
456
457
return data
457
458
458
459
459
- class TestDatetimeLikeDtype (TestDtype ):
460
- dtype = np .dtype ('M8[ns]' )
460
+ class DatetimeLike (Dtype ):
461
461
462
- # GH #12373: rolling functions raise ValueError on float32 data
463
- def setUp (self ):
464
- raise nose .SkipTest ("Skip rolling on DatetimeLike dtypes [{0}]." .format (self .dtype ))
462
+ def check_dtypes (self , f , f_name , d , d_name , exp ):
465
463
466
- def test_dtypes (self ):
467
- with tm .assertRaises (TypeError ):
468
- super (TestDatetimeLikeDtype , self ).test_dtypes ()
464
+ roll = d .rolling (window = self .window )
465
+
466
+ if f_name == 'count' :
467
+ result = f (roll )
468
+ assert_almost_equal (result , exp )
469
469
470
+ else :
471
+
472
+ # other methods not Implemented ATM
473
+ assert_raises (NotImplementedError , f , roll )
470
474
471
- class TestDtype_timedelta (TestDatetimeLikeDtype ):
475
+
476
+ class TestDtype_timedelta (DatetimeLike ):
472
477
dtype = np .dtype ('m8[ns]' )
473
478
474
479
475
- class TestDtype_datetime64UTC (TestDatetimeLikeDtype ):
480
+ class TestDtype_datetime (DatetimeLike ):
481
+ dtype = np .dtype ('M8[ns]' )
482
+
483
+
484
+ class TestDtype_datetime64UTC (DatetimeLike ):
476
485
dtype = 'datetime64[ns, UTC]'
477
486
487
+ def _create_data (self ):
488
+ raise nose .SkipTest ("direct creation of extension dtype "
489
+ "datetime64[ns, UTC] is not supported ATM" )
490
+
478
491
479
492
class TestMoments (Base ):
480
493
0 commit comments