1
1
# -*- coding: utf-8 -*-
2
2
3
+ import itertools
3
4
import pytest
4
5
import numpy as np
5
6
12
13
# Index / Series common tests which may trigger dtype coercions
13
14
###############################################################
14
15
16
+ @pytest .fixture (autouse = True , scope = 'class' )
17
+ def check_comprehensiveness (request ):
18
+ # Iterate over combination of dtype, method and klass
19
+ # and ensure that each are contained within a collected test
20
+ cls = request .cls
21
+ combos = itertools .product (cls .klasses , cls .dtypes , [cls .method ])
22
+
23
+ def has_test (combo ):
24
+ klass , dtype , method = combo
25
+ cls_funcs = request .node .session .items
26
+ return any (klass in x .name and dtype in x .name and
27
+ method in x .name for x in cls_funcs )
28
+
29
+ for combo in combos :
30
+ if not has_test (combo ):
31
+ msg = 'test method is not defined: {0}, {1}'
32
+ raise AssertionError (msg .format (type (cls ), combo ))
33
+
34
+ yield
15
35
16
36
class CoercionBase (object ):
17
37
@@ -34,15 +54,6 @@ def _assert(self, left, right, dtype):
34
54
assert left .dtype == dtype
35
55
assert right .dtype == dtype
36
56
37
- def test_has_comprehensive_tests (self ):
38
- for klass in self .klasses :
39
- for dtype in self .dtypes :
40
- method_name = 'test_{0}_{1}_{2}' .format (self .method ,
41
- klass , dtype )
42
- if not hasattr (self , method_name ):
43
- msg = 'test method is not defined: {0}, {1}'
44
- raise AssertionError (msg .format (type (self ), method_name ))
45
-
46
57
47
58
class TestSetitemCoercion (CoercionBase ):
48
59
@@ -276,6 +287,27 @@ def test_setitem_index_float64(self, val, exp_dtype):
276
287
exp_index = pd .Index ([1.1 , 2.1 , 3.1 , 4.1 , val ])
277
288
self ._assert_setitem_index_conversion (obj , val , exp_index , exp_dtype )
278
289
290
+ def test_setitem_series_period (self ):
291
+ pass
292
+
293
+ def test_setitem_index_complex128 (self ):
294
+ pass
295
+
296
+ def test_setitem_index_bool (self ):
297
+ pass
298
+
299
+ def test_setitem_index_datetime64 (self ):
300
+ pass
301
+
302
+ def test_setitem_index_datetime64tz (self ):
303
+ pass
304
+
305
+ def test_setitem_index_timedelta64 (self ):
306
+ pass
307
+
308
+ def test_setitem_index_period (self ):
309
+ pass
310
+
279
311
280
312
class TestInsertIndexCoercion (CoercionBase ):
281
313
@@ -329,8 +361,10 @@ def test_insert_index_float64(self, insert, coerced_val, coerced_dtype):
329
361
330
362
@pytest .mark .parametrize ('fill_val,exp_dtype' , [
331
363
(pd .Timestamp ('2012-01-01' ), 'datetime64[ns]' ),
332
- (pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' ), 'datetime64[ns, US/Eastern]' )])
333
- def test_insert_index_datetime64 (self , fill_val , exp_dtype ):
364
+ (pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' ),
365
+ 'datetime64[ns, US/Eastern]' )],
366
+ ids = ['datetime64' , 'datetime64tz' ])
367
+ def test_insert_index_datetimes (self , fill_val , exp_dtype ):
334
368
obj = pd .DatetimeIndex (['2011-01-01' , '2011-01-02' , '2011-01-03' ,
335
369
'2011-01-04' ], tz = fill_val .tz )
336
370
assert obj .dtype == exp_dtype
@@ -394,6 +428,12 @@ def test_insert_index_period(self, insert, coerced_val, coerced_dtype):
394
428
pd .Period ('2011-04' , freq = 'M' )], freq = 'M' )
395
429
self ._assert_insert_conversion (obj , insert , exp , coerced_dtype )
396
430
431
+ def test_insert_index_complex128 (self ):
432
+ pass
433
+
434
+ def test_insert_index_bool (self ):
435
+ pass
436
+
397
437
398
438
class TestWhereCoercion (CoercionBase ):
399
439
@@ -406,7 +446,8 @@ def _assert_where_conversion(self, original, cond, values,
406
446
res = target .where (cond , values )
407
447
self ._assert (res , expected , expected_dtype )
408
448
409
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ])
449
+ @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ],
450
+ ids = ['series' , 'index' ])
410
451
@pytest .mark .parametrize ("fill_val,exp_dtype" , [
411
452
(1 , np .object ),
412
453
(1.1 , np .object ),
@@ -433,7 +474,8 @@ def test_where_object(self, klass, fill_val,exp_dtype):
433
474
exp = klass (['a' , values [1 ], 'c' , values [3 ]])
434
475
self ._assert_where_conversion (obj , cond , values , exp , exp_dtype )
435
476
436
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ])
477
+ @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ],
478
+ ids = ['series' , 'index' ])
437
479
@pytest .mark .parametrize ("fill_val,exp_dtype" , [
438
480
(1 , np .int64 ),
439
481
(1.1 , np .float64 ),
@@ -456,7 +498,8 @@ def test_where_int64(self, klass, fill_val, exp_dtype):
456
498
exp = klass ([1 , values [1 ], 3 , values [3 ]])
457
499
self ._assert_where_conversion (obj , cond , values , exp , exp_dtype )
458
500
459
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ])
501
+ @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ],
502
+ ids = ['series' , 'index' ])
460
503
@pytest .mark .parametrize ("fill_val, exp_dtype" , [
461
504
(1 , np .float64 ),
462
505
(1.1 , np .float64 ),
@@ -523,7 +566,8 @@ def test_where_series_bool(self, fill_val, exp_dtype):
523
566
524
567
@pytest .mark .parametrize ("fill_val,exp_dtype" , [
525
568
(pd .Timestamp ('2012-01-01' ), 'datetime64[ns]' ),
526
- (pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' ), np .object )])
569
+ (pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' ), np .object )],
570
+ ids = ['datetime64' , 'datetime64tz' ])
527
571
def test_where_series_datetime64 (self , fill_val , exp_dtype ):
528
572
obj = pd .Series ([pd .Timestamp ('2011-01-01' ),
529
573
pd .Timestamp ('2011-01-02' ),
@@ -551,8 +595,9 @@ def test_where_series_datetime64(self, fill_val, exp_dtype):
551
595
552
596
@pytest .mark .parametrize ("fill_val,exp_dtype" , [
553
597
(pd .Timestamp ('2012-01-01' ), 'datetime64[ns]' ),
554
- (pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' ), np .object )])
555
- def test_where_index_datetime64 (self , fill_val , exp_dtype ):
598
+ (pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' ), np .object )],
599
+ ids = ['datetime64' , 'datetime64tz' ])
600
+ def test_where_index_datetime (self , fill_val , exp_dtype ):
556
601
obj = pd .Index ([pd .Timestamp ('2011-01-01' ),
557
602
pd .Timestamp ('2011-01-02' ),
558
603
pd .Timestamp ('2011-01-03' ),
@@ -577,6 +622,30 @@ def test_where_index_datetime64(self, fill_val, exp_dtype):
577
622
self ._assert_where_conversion (obj , cond , values , exp , exp_dtype )
578
623
pytest .xfail ("datetime64 + datetime64 -> datetime64 must support scalar" )
579
624
625
+ def test_where_index_complex128 (self ):
626
+ pass
627
+
628
+ def test_where_index_bool (self ):
629
+ pass
630
+
631
+ def test_where_series_datetime64tz (self ):
632
+ pass
633
+
634
+ def test_where_series_timedelta64 (self ):
635
+ pass
636
+
637
+ def test_where_series_period (self ):
638
+ pass
639
+
640
+ def test_where_index_datetime64tz (self ):
641
+ pass
642
+
643
+ def test_where_index_timedelta64 (self ):
644
+ pass
645
+
646
+ def test_where_index_period (self ):
647
+ pass
648
+
580
649
581
650
class TestFillnaSeriesCoercion (CoercionBase ):
582
651
@@ -594,7 +663,8 @@ def _assert_fillna_conversion(self, original, value,
594
663
res = target .fillna (value )
595
664
self ._assert (res , expected , expected_dtype )
596
665
597
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ])
666
+ @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ],
667
+ ids = ['series' , 'index' ])
598
668
@pytest .mark .parametrize ("fill_val, fill_dtype" , [
599
669
(1 , np .object ),
600
670
(1.1 , np .object ),
@@ -607,7 +677,8 @@ def test_fillna_object(self, klass, fill_val, fill_dtype):
607
677
exp = klass (['a' , fill_val , 'c' , 'd' ])
608
678
self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
609
679
610
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ])
680
+ @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ],
681
+ ids = ['series' , 'index' ])
611
682
@pytest .mark .parametrize ("fill_val,filled_val,fill_dtype" , [
612
683
(1 , 1.0 , np .float64 ),
613
684
(1.1 , 1.1 , np .float64 ),
@@ -637,13 +708,15 @@ def test_fillna_series_complex128(self, fill_val, fill_dtype):
637
708
exp = pd .Series ([1 + 1j , fill_val , 3 + 3j , 4 + 4j ])
638
709
self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
639
710
640
- @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ])
711
+ @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ],
712
+ ids = ['series' , 'index' ])
641
713
@pytest .mark .parametrize ("fill_val,fill_dtype" , [
642
714
(pd .Timestamp ('2012-01-01' ), 'datetime64[ns]' ),
643
715
(pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' ), np .object ),
644
- (1 , np .object ),
645
- ('x' , np .object )])
646
- def test_fillna_datetime64 (self , klass , fill_val , fill_dtype ):
716
+ (1 , np .object ), ('x' , np .object )],
717
+ ids = ['datetime64' , 'datetime64tz' ,
718
+ 'object' , 'object' ])
719
+ def test_fillna_datetime (self , klass , fill_val , fill_dtype ):
647
720
obj = klass ([pd .Timestamp ('2011-01-01' ),
648
721
pd .NaT ,
649
722
pd .Timestamp ('2011-01-03' ),
@@ -679,15 +752,37 @@ def test_fillna_datetime64tz(self, klass, fill_val, fill_dtype):
679
752
pd .Timestamp ('2011-01-04' , tz = tz )])
680
753
self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
681
754
755
+ def test_fillna_series_int64 (self ):
756
+ # int can't hold NaN
757
+ pass
758
+
759
+ def test_fillna_index_int64 (self ):
760
+ pass
761
+
762
+ def test_fillna_series_bool (self ):
763
+ # bool can't hold NaN
764
+ pass
765
+
766
+ def test_fillna_index_bool (self ):
767
+ pass
768
+
769
+ def test_fillna_series_timedelta64 (self ):
770
+ pass
682
771
683
- @pytest .mark .parametrize ('how' , ['dict' , 'series' ])
684
- @pytest .mark .parametrize ('to_key' , [
685
- 'object' , 'int64' , 'float64' , 'complex128' , 'bool' , 'datetime64[ns]' ,
686
- 'datetime64[ns, UTC]' , 'datetime64[ns, US/Eastern]' , 'timedelta64[ns]' ])
687
- @pytest .mark .parametrize ('from_key' , [
688
- 'object' , 'int64' , 'float64' , 'complex128' , 'bool' , 'datetime64[ns]' ,
689
- 'datetime64[ns, UTC]' , 'datetime64[ns, US/Eastern]' , 'timedelta64[ns]' ])
690
- class TestReplaceSeriesCoercion (object ):
772
+ def test_fillna_series_period (self ):
773
+ pass
774
+
775
+ def test_fillna_index_timedelta64 (self ):
776
+ pass
777
+
778
+ def test_fillna_index_period (self ):
779
+ pass
780
+
781
+
782
+ class TestReplaceSeriesCoercion (CoercionBase ):
783
+
784
+ klasses = ['series' ]
785
+ method = 'replace'
691
786
692
787
rep = {}
693
788
rep ['object' ] = ['a' , 'b' ]
@@ -707,6 +802,16 @@ class TestReplaceSeriesCoercion(object):
707
802
rep ['timedelta64[ns]' ] = [pd .Timedelta ('1 day' ),
708
803
pd .Timedelta ('2 day' )]
709
804
805
+ @pytest .mark .parametrize ('how' , ['dict' , 'series' ])
806
+ @pytest .mark .parametrize ('to_key' , [
807
+ 'object' , 'int64' , 'float64' , 'complex128' , 'bool' , 'datetime64[ns]' ,
808
+ 'datetime64[ns, UTC]' , 'datetime64[ns, US/Eastern]' , 'timedelta64[ns]' ],
809
+ ids = ['object' , 'int64' , 'float64' , 'complex128' ,
810
+ 'bool' , 'datetime64' , 'datetime64tz' , 'datetime64tz' ,
811
+ 'timedelta64' ])
812
+ @pytest .mark .parametrize ('from_key' , [
813
+ 'object' , 'int64' , 'float64' , 'complex128' , 'bool' , 'datetime64[ns]' ,
814
+ 'datetime64[ns, UTC]' , 'datetime64[ns, US/Eastern]' , 'timedelta64[ns]' ])
710
815
def test_replace_series (self , how , to_key , from_key ):
711
816
if from_key == 'bool' and how == 'series' and compat .PY3 :
712
817
# doesn't work in PY3, though ...dict_from_bool works fine
@@ -746,3 +851,6 @@ def test_replace_series(self, how, to_key, from_key):
746
851
assert exp .dtype == to_key
747
852
748
853
tm .assert_series_equal (result , exp )
854
+
855
+ def test_replace_series_period (self ):
856
+ pass
0 commit comments