@@ -1018,219 +1018,6 @@ class TestGantt(NumpyTestUtilsMixin, TestCase):
1018
1018
1019
1019
def test_df_dataframe (self ):
1020
1020
1021
- # validate df when it is a dataframe
1022
-
1021
+ # validate dataframe has correct column names
1023
1022
df1 = pd .DataFrame ([[2 , 'Apple' ]], columns = ['Numbers' , 'Fruit' ])
1024
1023
self .assertRaises (PlotlyError , tls .FigureFactory .create_gantt , df1 )
1025
-
1026
- df2 = pd .DataFrame ([['Job A' , '2009-01-01' , '2009-02-30' , 25 ],
1027
- ['Job B' , '2009-01-01' , '2009-02-30' , '25' ]],
1028
- columns = ['Task' , 'Start' , 'Finish' , 'Complete' ])
1029
- self .assertRaisesRegexp (PlotlyError ,
1030
- "The values in the 'Complete' column must "
1031
- "be between 0 and 100." ,
1032
- tls .FigureFactory .create_gantt , df2 )
1033
-
1034
- def test_df_list (self ):
1035
-
1036
- # validate df when it is a list
1037
-
1038
- df1 = 42
1039
- self .assertRaisesRegexp (PlotlyError ,
1040
- "You must input either a dataframe or a list "
1041
- "of dictionaries." ,
1042
- tls .FigureFactory .create_gantt , df1 )
1043
-
1044
- df2 = []
1045
- self .assertRaisesRegexp (PlotlyError ,
1046
- "Your list is empty. It must contain "
1047
- "at least one dictionary." ,
1048
- tls .FigureFactory .create_gantt , df2 )
1049
-
1050
- df3 = [42 ]
1051
- self .assertRaisesRegexp (PlotlyError ,
1052
- "Your list must only include dictionaries." ,
1053
- tls .FigureFactory .create_gantt , df3 )
1054
-
1055
- df4 = [{'apple' : 2 }]
1056
- self .assertRaises (PlotlyError , tls .FigureFactory .create_gantt , df4 )
1057
-
1058
- df5 = [{'Task' : 'A Job' ,
1059
- 'Start' : '2009-01-01' ,
1060
- 'Finish' : '2009-02-30' },
1061
- {'Task' : 'A Job' ,
1062
- 'Start' : '2009-01-01' ,
1063
- 'Finish' : '2009-02-30' ,
1064
- 'Complete' : 25 }]
1065
- self .assertRaisesRegexp (PlotlyError ,
1066
- "If you are using 'Complete' as a dictionary "
1067
- "key, make sure each dictionary has this key "
1068
- "with an assigned value between 0 and 100." ,
1069
- tls .FigureFactory .create_gantt , df5 )
1070
-
1071
- df6 = [{'Task' : 'A Job' ,
1072
- 'Start' : '2009-01-01' ,
1073
- 'Finish' : '2009-02-30' ,
1074
- 'Complete' : 55 },
1075
- {'Task' : 'A Job' ,
1076
- 'Start' : '2009-01-01' ,
1077
- 'Finish' : '2009-02-30' ,
1078
- 'Complete' : 'string' }]
1079
- self .assertRaisesRegexp (PlotlyError ,
1080
- "The values in the 'Complete' column must "
1081
- "be between 0 and 100." ,
1082
- tls .FigureFactory .create_gantt , df6 )
1083
-
1084
- def test_valid_colors (self ):
1085
-
1086
- # check: if color choices are valid
1087
-
1088
- df = [{'Task' : 'A Job' ,
1089
- 'Start' : '2009-01-01' ,
1090
- 'Finish' : '2009-02-30' ,
1091
- 'Complete' : 55 },
1092
- {'Task' : 'A Job' ,
1093
- 'Start' : '2009-01-01' ,
1094
- 'Finish' : '2009-02-30' ,
1095
- 'Complete' : 65 }]
1096
-
1097
- self .assertRaises (PlotlyError , tls .FigureFactory .create_gantt ,
1098
- df , colors = 'Weird' )
1099
-
1100
- pattern1 = (
1101
- "If 'colors' is a list then its items must be tripets of the "
1102
- "form a,b,c or 'rgbx,y,z' where a,b,c are between 0 and 1 "
1103
- "inclusive and x,y,z are between 0 and 255 inclusive."
1104
- )
1105
-
1106
- self .assertRaisesRegexp (PlotlyError , pattern1 ,
1107
- tls .FigureFactory .create_gantt , df , colors = 25 )
1108
-
1109
- pattern2 = (
1110
- "Whoops! The elements in your rgb colors tuples "
1111
- "cannot exceed 255.0."
1112
- )
1113
-
1114
- self .assertRaisesRegexp (PlotlyError , pattern2 ,
1115
- tls .FigureFactory .create_gantt , df ,
1116
- colors = ['rgb(1, 2, 3)' , 'rgb(300, 2, 3)' ])
1117
-
1118
- pattern3 = (
1119
- "Whoops! The elements in your rgb colors tuples "
1120
- "cannot exceed 1.0."
1121
- )
1122
-
1123
- self .assertRaisesRegexp (PlotlyError , pattern3 ,
1124
- tls .FigureFactory .create_gantt , df ,
1125
- colors = [(0.1 , 0.2 , 0.3 ), (0.6 , 0.8 , 1.2 )])
1126
-
1127
- def test_use_colorscale (self ):
1128
-
1129
- # checks: 'Complete' in inputted array or list
1130
-
1131
- df = [{'Task' : 'A Job' ,
1132
- 'Start' : '2009-01-01' ,
1133
- 'Finish' : '2009-02-30' },
1134
- {'Task' : 'A Job' ,
1135
- 'Start' : '2009-01-01' ,
1136
- 'Finish' : '2009-02-30' }]
1137
-
1138
- pattern = (
1139
- "In order to use colorscale there must be a "
1140
- "'Complete' column in the chart."
1141
- )
1142
- self .assertRaisesRegexp (PlotlyError , pattern ,
1143
- tls .FigureFactory .create_gantt , df ,
1144
- use_colorscale = True )
1145
-
1146
- def test_gantt_all_args (self ):
1147
-
1148
- # check if gantt chart matches with expected output
1149
-
1150
- df = [dict (Task = "Run" ,
1151
- Start = '2010-01-01' ,
1152
- Finish = '2011-02-02' ,
1153
- Complete = 0 ),
1154
- dict (Task = "Fast" ,
1155
- Start = '2011-01-01' ,
1156
- Finish = '2012-06-05' ,
1157
- Complete = 25 )]
1158
-
1159
- test_gantt_chart = tls .FigureFactory .create_gantt (
1160
- df , colors = 'Blues' , use_colorscale = True , reverse_colors = True ,
1161
- title = 'Title' , bar_width = 0.5 , showgrid_x = True , showgrid_y = True ,
1162
- height = 500 , width = 500
1163
- )
1164
-
1165
- exp_gantt_chart = {
1166
- 'data' : [{'marker' : {'color' : 'white' },
1167
- 'name' : '' ,
1168
- 'x' : ['2010-01-01' , '2011-02-02' ],
1169
- 'y' : [0 , 0 ]},
1170
- {'marker' : {'color' : 'white' },
1171
- 'name' : '' ,
1172
- 'x' : ['2011-01-01' , '2012-06-05' ],
1173
- 'y' : [1 , 1 ]}],
1174
- 'layout' : {'height' : 500 ,
1175
- 'hovermode' : 'closest' ,
1176
- 'shapes' : [{'fillcolor' : 'rgb(220.0, 220.0, 220.0)' ,
1177
- 'line' : {'width' : 0 },
1178
- 'opacity' : 1 ,
1179
- 'type' : 'rect' ,
1180
- 'x0' : '2010-01-01' ,
1181
- 'x1' : '2011-02-02' ,
1182
- 'xref' : 'x' ,
1183
- 'y0' : - 0.5 ,
1184
- 'y1' : 0.5 ,
1185
- 'yref' : 'y' },
1186
- {'fillcolor' : 'rgb(166.25, 167.5, 208.0)' ,
1187
- 'line' : {'width' : 0 },
1188
- 'opacity' : 1 ,
1189
- 'type' : 'rect' ,
1190
- 'x0' : '2011-01-01' ,
1191
- 'x1' : '2012-06-05' ,
1192
- 'xref' : 'x' ,
1193
- 'y0' : 0.5 ,
1194
- 'y1' : 1.5 ,
1195
- 'yref' : 'y' }],
1196
- 'showlegend' : False ,
1197
- 'title' : 'Title' ,
1198
- 'width' : 500 ,
1199
- 'xaxis' : {
1200
- 'rangeselector' : {
1201
- 'buttons' : [{'count' : 7 , 'label' : '1w' ,
1202
- 'step' : 'day' ,
1203
- 'stepmode' : 'backward' },
1204
- {'count' : 1 , 'label' : '1m' ,
1205
- 'step' : 'month' ,
1206
- 'stepmode' : 'backward' },
1207
- {'count' : 6 , 'label' : '6m' ,
1208
- 'step' : 'month' ,
1209
- 'stepmode' : 'backward' },
1210
- {'count' : 1 , 'label' : 'YTD' ,
1211
- 'step' : 'year' ,
1212
- 'stepmode' : 'todate' },
1213
- {'count' : 1 , 'label' : '1y' ,
1214
- 'step' : 'year' ,
1215
- 'stepmode' : 'backward' },
1216
- {'step' : 'all' }]
1217
- },
1218
- 'showgrid' : True ,
1219
- 'type' : 'date' ,
1220
- 'zeroline' : False },
1221
- 'yaxis' : {'autorange' : False ,
1222
- 'range' : [- 1 , 3 ],
1223
- 'showgrid' : True ,
1224
- 'ticktext' : ['Run' , 'Fast' ],
1225
- 'tickvals' : [0 , 1 ],
1226
- 'zeroline' : False }}
1227
- }
1228
-
1229
- self .assert_dict_equal (test_gantt_chart ['data' ][0 ],
1230
- exp_gantt_chart ['data' ][0 ])
1231
-
1232
- self .assert_dict_equal (test_gantt_chart ['data' ][1 ],
1233
- exp_gantt_chart ['data' ][1 ])
1234
-
1235
- self .assert_dict_equal (test_gantt_chart ['layout' ],
1236
- exp_gantt_chart ['layout' ])
0 commit comments