@@ -883,277 +883,100 @@ class TestFillnaSeriesCoercion(CoercionBase):
883883
884884 method = 'fillna'
885885
886+ def test_has_comprehensive_tests (self ):
887+ pass
888+
886889 def _assert_fillna_conversion (self , original , value ,
887890 expected , expected_dtype ):
888891 """ test coercion triggered by fillna """
889892 target = original .copy ()
890893 res = target .fillna (value )
891894 self ._assert (res , expected , expected_dtype )
892895
893- def _fillna_object_common (self , klass ):
896+ @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ])
897+ @pytest .mark .parametrize ("fill_val, fill_dtype" , [
898+ (1 , np .object ),
899+ (1.1 , np .object ),
900+ (1 + 1j , np .object ),
901+ (True , np .object )])
902+ def test_fillna_object (self , klass , fill_val , fill_dtype ):
894903 obj = klass (['a' , np .nan , 'c' , 'd' ])
895904 assert obj .dtype == np .object
896905
897- # object + int -> object
898- exp = klass (['a' , 1 , 'c' , 'd' ])
899- self ._assert_fillna_conversion (obj , 1 , exp , np .object )
906+ exp = klass (['a' , fill_val , 'c' , 'd' ])
907+ self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
900908
901- # object + float -> object
902- exp = klass (['a' , 1.1 , 'c' , 'd' ])
903- self ._assert_fillna_conversion (obj , 1.1 , exp , np .object )
904-
905- # object + complex -> object
906- exp = klass (['a' , 1 + 1j , 'c' , 'd' ])
907- self ._assert_fillna_conversion (obj , 1 + 1j , exp , np .object )
908-
909- # object + bool -> object
910- exp = klass (['a' , True , 'c' , 'd' ])
911- self ._assert_fillna_conversion (obj , True , exp , np .object )
912-
913- def test_fillna_series_object (self ):
914- self ._fillna_object_common (pd .Series )
915-
916- def test_fillna_index_object (self ):
917- self ._fillna_object_common (pd .Index )
918-
919- def test_fillna_series_int64 (self ):
920- # int can't hold NaN
921- pass
922-
923- def test_fillna_index_int64 (self ):
924- pass
925-
926- def _fillna_float64_common (self , klass , complex ):
909+ @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ])
910+ @pytest .mark .parametrize ("fill_val,filled_val,fill_dtype" , [
911+ (1 , 1.0 , np .float64 ),
912+ (1.1 , 1.1 , np .float64 ),
913+ (1 + 1j , 1 + 1j , np .complex128 ),
914+ (True , True , np .object )])
915+ def test_fillna_float64 (self , klass , fill_val , filled_val , fill_dtype ):
927916 obj = klass ([1.1 , np .nan , 3.3 , 4.4 ])
928917 assert obj .dtype == np .float64
929918
930- # float + int -> float
931- exp = klass ([1.1 , 1.0 , 3.3 , 4.4 ])
932- self ._assert_fillna_conversion (obj , 1 , exp , np .float64 )
933-
934- # float + float -> float
935- exp = klass ([1.1 , 1.1 , 3.3 , 4.4 ])
936- self ._assert_fillna_conversion (obj , 1.1 , exp , np .float64 )
937-
919+ exp = klass ([1.1 , filled_val , 3.3 , 4.4 ])
938920 # float + complex -> we don't support a complex Index
939921 # complex for Series,
940922 # object for Index
941- exp = klass ([1.1 , 1 + 1j , 3.3 , 4.4 ])
942- self ._assert_fillna_conversion (obj , 1 + 1j , exp , complex )
943-
944- # float + bool -> object
945- exp = klass ([1.1 , True , 3.3 , 4.4 ])
946- self ._assert_fillna_conversion (obj , True , exp , np .object )
947-
948- def test_fillna_series_float64 (self ):
949- self ._fillna_float64_common (pd .Series , complex = np .complex128 )
950-
951- def test_fillna_index_float64 (self ):
952- self ._fillna_float64_common (pd .Index , complex = np .object )
953-
954- def test_fillna_series_complex128 (self ):
923+ if fill_dtype == np .complex128 and klass == pd .Index :
924+ fill_dtype = np .object
925+ self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
926+
927+ @pytest .mark .parametrize ("fill_val,fill_dtype" , [
928+ (1 , np .complex128 ),
929+ (1.1 , np .complex128 ),
930+ (1 + 1j , np .complex128 ),
931+ (True , np .object )])
932+ def test_fillna_series_complex128 (self , fill_val , fill_dtype ):
955933 obj = pd .Series ([1 + 1j , np .nan , 3 + 3j , 4 + 4j ])
956934 assert obj .dtype == np .complex128
957935
958- # complex + int -> complex
959- exp = pd .Series ([1 + 1j , 1 , 3 + 3j , 4 + 4j ])
960- self ._assert_fillna_conversion (obj , 1 , exp , np .complex128 )
961-
962- # complex + float -> complex
963- exp = pd .Series ([1 + 1j , 1.1 , 3 + 3j , 4 + 4j ])
964- self ._assert_fillna_conversion (obj , 1.1 , exp , np .complex128 )
965-
966- # complex + complex -> complex
967- exp = pd .Series ([1 + 1j , 1 + 1j , 3 + 3j , 4 + 4j ])
968- self ._assert_fillna_conversion (obj , 1 + 1j , exp , np .complex128 )
969-
970- # complex + bool -> object
971- exp = pd .Series ([1 + 1j , True , 3 + 3j , 4 + 4j ])
972- self ._assert_fillna_conversion (obj , True , exp , np .object )
973-
974- def test_fillna_index_complex128 (self ):
975- self ._fillna_float64_common (pd .Index , complex = np .object )
976-
977- def test_fillna_series_bool (self ):
978- # bool can't hold NaN
979- pass
980-
981- def test_fillna_index_bool (self ):
982- pass
983-
984- def test_fillna_series_datetime64 (self ):
985- obj = pd .Series ([pd .Timestamp ('2011-01-01' ),
986- pd .NaT ,
987- pd .Timestamp ('2011-01-03' ),
988- pd .Timestamp ('2011-01-04' )])
989- assert obj .dtype == 'datetime64[ns]'
990-
991- # datetime64 + datetime64 => datetime64
992- exp = pd .Series ([pd .Timestamp ('2011-01-01' ),
993- pd .Timestamp ('2012-01-01' ),
994- pd .Timestamp ('2011-01-03' ),
995- pd .Timestamp ('2011-01-04' )])
996- self ._assert_fillna_conversion (obj , pd .Timestamp ('2012-01-01' ),
997- exp , 'datetime64[ns]' )
998-
999- # datetime64 + datetime64tz => object
1000- exp = pd .Series ([pd .Timestamp ('2011-01-01' ),
1001- pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' ),
1002- pd .Timestamp ('2011-01-03' ),
1003- pd .Timestamp ('2011-01-04' )])
1004- value = pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' )
1005- self ._assert_fillna_conversion (obj , value , exp , np .object )
1006-
1007- # datetime64 + int => object
1008- exp = pd .Series ([pd .Timestamp ('2011-01-01' ),
1009- 1 ,
1010- pd .Timestamp ('2011-01-03' ),
1011- pd .Timestamp ('2011-01-04' )])
1012- self ._assert_fillna_conversion (obj , 1 , exp , 'object' )
1013-
1014- # datetime64 + object => object
1015- exp = pd .Series ([pd .Timestamp ('2011-01-01' ),
1016- 'x' ,
1017- pd .Timestamp ('2011-01-03' ),
1018- pd .Timestamp ('2011-01-04' )])
1019- self ._assert_fillna_conversion (obj , 'x' , exp , np .object )
1020-
1021- def test_fillna_series_datetime64tz (self ):
1022- tz = 'US/Eastern'
1023-
1024- obj = pd .Series ([pd .Timestamp ('2011-01-01' , tz = tz ),
1025- pd .NaT ,
1026- pd .Timestamp ('2011-01-03' , tz = tz ),
1027- pd .Timestamp ('2011-01-04' , tz = tz )])
1028- assert obj .dtype == 'datetime64[ns, US/Eastern]'
1029-
1030- # datetime64tz + datetime64tz => datetime64tz
1031- exp = pd .Series ([pd .Timestamp ('2011-01-01' , tz = tz ),
1032- pd .Timestamp ('2012-01-01' , tz = tz ),
1033- pd .Timestamp ('2011-01-03' , tz = tz ),
1034- pd .Timestamp ('2011-01-04' , tz = tz )])
1035- value = pd .Timestamp ('2012-01-01' , tz = tz )
1036- self ._assert_fillna_conversion (obj , value , exp ,
1037- 'datetime64[ns, US/Eastern]' )
1038-
1039- # datetime64tz + datetime64 => object
1040- exp = pd .Series ([pd .Timestamp ('2011-01-01' , tz = tz ),
1041- pd .Timestamp ('2012-01-01' ),
1042- pd .Timestamp ('2011-01-03' , tz = tz ),
1043- pd .Timestamp ('2011-01-04' , tz = tz )])
1044- value = pd .Timestamp ('2012-01-01' )
1045- self ._assert_fillna_conversion (obj , value , exp , np .object )
1046-
1047- # datetime64tz + datetime64tz(different tz) => object
1048- exp = pd .Series ([pd .Timestamp ('2011-01-01' , tz = tz ),
1049- pd .Timestamp ('2012-01-01' , tz = 'Asia/Tokyo' ),
1050- pd .Timestamp ('2011-01-03' , tz = tz ),
1051- pd .Timestamp ('2011-01-04' , tz = tz )])
1052- value = pd .Timestamp ('2012-01-01' , tz = 'Asia/Tokyo' )
1053- self ._assert_fillna_conversion (obj , value , exp , np .object )
1054-
1055- # datetime64tz + int => object
1056- exp = pd .Series ([pd .Timestamp ('2011-01-01' , tz = tz ),
1057- 1 ,
1058- pd .Timestamp ('2011-01-03' , tz = tz ),
1059- pd .Timestamp ('2011-01-04' , tz = tz )])
1060- self ._assert_fillna_conversion (obj , 1 , exp , np .object )
1061-
1062- # datetime64tz + object => object
1063- exp = pd .Series ([pd .Timestamp ('2011-01-01' , tz = tz ),
1064- 'x' ,
1065- pd .Timestamp ('2011-01-03' , tz = tz ),
1066- pd .Timestamp ('2011-01-04' , tz = tz )])
1067- self ._assert_fillna_conversion (obj , 'x' , exp , np .object )
1068-
1069- def test_fillna_series_timedelta64 (self ):
1070- pass
1071-
1072- def test_fillna_series_period (self ):
1073- pass
1074-
1075- def test_fillna_index_datetime64 (self ):
1076- obj = pd .DatetimeIndex (['2011-01-01' , 'NaT' , '2011-01-03' ,
1077- '2011-01-04' ])
936+ exp = pd .Series ([1 + 1j , fill_val , 3 + 3j , 4 + 4j ])
937+ self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
938+
939+ @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ])
940+ @pytest .mark .parametrize ("fill_val,fill_dtype" , [
941+ (pd .Timestamp ('2012-01-01' ), 'datetime64[ns]' ),
942+ (pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' ), np .object ),
943+ (1 , np .object ),
944+ ('x' , np .object )])
945+ def test_fillna_datetime64 (self , klass , fill_val , fill_dtype ):
946+ obj = klass ([pd .Timestamp ('2011-01-01' ),
947+ pd .NaT ,
948+ pd .Timestamp ('2011-01-03' ),
949+ pd .Timestamp ('2011-01-04' )])
1078950 assert obj .dtype == 'datetime64[ns]'
1079951
1080- # datetime64 + datetime64 => datetime64
1081- exp = pd .DatetimeIndex (['2011-01-01' , '2012-01-01' ,
1082- '2011-01-03' , '2011-01-04' ])
1083- self ._assert_fillna_conversion (obj , pd .Timestamp ('2012-01-01' ),
1084- exp , 'datetime64[ns]' )
1085-
1086- # datetime64 + datetime64tz => object
1087- exp = pd .Index ([pd .Timestamp ('2011-01-01' ),
1088- pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' ),
1089- pd .Timestamp ('2011-01-03' ),
1090- pd .Timestamp ('2011-01-04' )])
1091- value = pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' )
1092- self ._assert_fillna_conversion (obj , value , exp , np .object )
1093-
1094- # datetime64 + int => object
1095- exp = pd .Index ([pd .Timestamp ('2011-01-01' ),
1096- 1 ,
1097- pd .Timestamp ('2011-01-03' ),
1098- pd .Timestamp ('2011-01-04' )])
1099- self ._assert_fillna_conversion (obj , 1 , exp , np .object )
1100-
1101- # datetime64 + object => object
1102- exp = pd .Index ([pd .Timestamp ('2011-01-01' ),
1103- 'x' ,
1104- pd .Timestamp ('2011-01-03' ),
1105- pd .Timestamp ('2011-01-04' )])
1106- self ._assert_fillna_conversion (obj , 'x' , exp , np .object )
1107-
1108- def test_fillna_index_datetime64tz (self ):
952+ exp = klass ([pd .Timestamp ('2011-01-01' ),
953+ fill_val ,
954+ pd .Timestamp ('2011-01-03' ),
955+ pd .Timestamp ('2011-01-04' )])
956+ self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
957+
958+ @pytest .mark .parametrize ("klass" , [pd .Series , pd .Index ])
959+ @pytest .mark .parametrize ("fill_val,fill_dtype" , [
960+ (pd .Timestamp ('2012-01-01' , tz = 'US/Eastern' ),
961+ 'datetime64[ns, US/Eastern]' ),
962+ (pd .Timestamp ('2012-01-01' ), np .object ),
963+ (pd .Timestamp ('2012-01-01' , tz = 'Asia/Tokyo' ), np .object ),
964+ (1 , np .object ),
965+ ('x' , np .object )])
966+ def test_fillna_datetime64tz (self , klass , fill_val , fill_dtype ):
1109967 tz = 'US/Eastern'
1110968
1111- obj = pd .DatetimeIndex (['2011-01-01' , 'NaT' , '2011-01-03' ,
1112- '2011-01-04' ], tz = tz )
969+ obj = klass ([pd .Timestamp ('2011-01-01' , tz = tz ),
970+ pd .NaT ,
971+ pd .Timestamp ('2011-01-03' , tz = tz ),
972+ pd .Timestamp ('2011-01-04' , tz = tz )])
1113973 assert obj .dtype == 'datetime64[ns, US/Eastern]'
1114974
1115- # datetime64tz + datetime64tz => datetime64tz
1116- exp = pd .DatetimeIndex (['2011-01-01' , '2012-01-01' ,
1117- '2011-01-03' , '2011-01-04' ], tz = tz )
1118- value = pd .Timestamp ('2012-01-01' , tz = tz )
1119- self ._assert_fillna_conversion (obj , value , exp ,
1120- 'datetime64[ns, US/Eastern]' )
1121-
1122- # datetime64tz + datetime64 => object
1123- exp = pd .Index ([pd .Timestamp ('2011-01-01' , tz = tz ),
1124- pd .Timestamp ('2012-01-01' ),
1125- pd .Timestamp ('2011-01-03' , tz = tz ),
1126- pd .Timestamp ('2011-01-04' , tz = tz )])
1127- value = pd .Timestamp ('2012-01-01' )
1128- self ._assert_fillna_conversion (obj , value , exp , np .object )
1129-
1130- # datetime64tz + datetime64tz(different tz) => object
1131- exp = pd .Index ([pd .Timestamp ('2011-01-01' , tz = tz ),
1132- pd .Timestamp ('2012-01-01' , tz = 'Asia/Tokyo' ),
1133- pd .Timestamp ('2011-01-03' , tz = tz ),
1134- pd .Timestamp ('2011-01-04' , tz = tz )])
1135- value = pd .Timestamp ('2012-01-01' , tz = 'Asia/Tokyo' )
1136- self ._assert_fillna_conversion (obj , value , exp , np .object )
1137-
1138- # datetime64tz + int => object
1139- exp = pd .Index ([pd .Timestamp ('2011-01-01' , tz = tz ),
1140- 1 ,
1141- pd .Timestamp ('2011-01-03' , tz = tz ),
1142- pd .Timestamp ('2011-01-04' , tz = tz )])
1143- self ._assert_fillna_conversion (obj , 1 , exp , np .object )
1144-
1145- # datetime64tz + object => object
1146- exp = pd .Index ([pd .Timestamp ('2011-01-01' , tz = tz ),
1147- 'x' ,
1148- pd .Timestamp ('2011-01-03' , tz = tz ),
1149- pd .Timestamp ('2011-01-04' , tz = tz )])
1150- self ._assert_fillna_conversion (obj , 'x' , exp , np .object )
1151-
1152- def test_fillna_index_timedelta64 (self ):
1153- pass
1154-
1155- def test_fillna_index_period (self ):
1156- pass
975+ exp = klass ([pd .Timestamp ('2011-01-01' , tz = tz ),
976+ fill_val ,
977+ pd .Timestamp ('2011-01-03' , tz = tz ),
978+ pd .Timestamp ('2011-01-04' , tz = tz )])
979+ self ._assert_fillna_conversion (obj , fill_val , exp , fill_dtype )
1157980
1158981
1159982@pytest .mark .parametrize ('how' , ['dict' , 'series' ])
0 commit comments