23
23
+ ["ids" , "error_x" , "error_x_minus" , "error_y" , "error_y_minus" , "error_z" ]
24
24
+ ["error_z_minus" , "lat" , "lon" , "locations" , "animation_group" ]
25
25
)
26
- array_attrables = ["dimensions" , "custom_data" , "hover_data" , "path" ]
26
+ array_attrables = ["dimensions" , "custom_data" , "hover_data" , "path" , "wide_cols" ]
27
27
group_attrables = ["animation_frame" , "facet_row" , "facet_col" , "line_group" ]
28
28
renameable_group_attrables = [
29
29
"color" , # renamed to marker.color or line.color in infer_config
@@ -942,7 +942,6 @@ def build_dataframe(args, constructor):
942
942
df_provided = args ["data_frame" ] is not None
943
943
if df_provided and not isinstance (args ["data_frame" ], pd .DataFrame ):
944
944
args ["data_frame" ] = pd .DataFrame (args ["data_frame" ])
945
-
946
945
df_input = args ["data_frame" ]
947
946
948
947
no_x = args .get ("x" , None ) is None
@@ -952,10 +951,35 @@ def build_dataframe(args, constructor):
952
951
wide_id_vars = set ()
953
952
954
953
if wide_mode :
955
- df_output = df_input
956
- var_name = df_output .columns .name or "_column_"
957
- else :
958
- df_output = pd .DataFrame ()
954
+ # currently assuming that df_provided == True
955
+ args ["wide_cols" ] = [df_input .index ] + list (df_input .columns )
956
+ var_name = df_input .columns .name or "_column_"
957
+ index_name = df_input .index .name or "index"
958
+ wide_id_vars .add (index_name )
959
+
960
+ """
961
+ wide_x detection
962
+ - if scalar = False
963
+ - else if list of lists = True
964
+ - else if not df_provided = False
965
+ - else if contents are unique and are contained in columns = True
966
+ - else = False
967
+
968
+
969
+ wide detection:
970
+ - if no_x and no_y = wide mode
971
+ - else if wide_x and wide_y = error
972
+ - else if wide_x xor wide_y = wide mode
973
+ - else = long mode
974
+
975
+ so what we want is:
976
+ - y = [col col] -> melt just those
977
+ - x = [col col] -> melt just those but swap the orientation? except in hist mode
978
+ - y = [col col] / x=col -> melt just those and force x to not be the index ... what about hist
979
+ - y = [col col] / x=[col col] -> error
980
+ """
981
+
982
+ df_output = pd .DataFrame ()
959
983
960
984
missing_bar_dim = None
961
985
if constructor in [go .Scatter , go .Bar ] and (no_x != no_y ):
@@ -1110,7 +1134,8 @@ def build_dataframe(args, constructor):
1110
1134
args [field_name ] = str (col_name )
1111
1135
else :
1112
1136
args [field_name ][i ] = str (col_name )
1113
- wide_id_vars .add (str (col_name ))
1137
+ if field_name != "wide_cols" :
1138
+ wide_id_vars .add (str (col_name ))
1114
1139
1115
1140
if missing_bar_dim and constructor == go .Bar :
1116
1141
# now that we've populated df_output, we check to see if the non-missing
@@ -1134,14 +1159,13 @@ def build_dataframe(args, constructor):
1134
1159
df_output [col_name ] = constants [col_name ]
1135
1160
1136
1161
if wide_mode :
1137
- # TODO multi-level index
1138
- # TODO multi-level columns
1139
- index_name = df_output .index .name or "index"
1140
- wide_id_vars .add (index_name )
1141
- if index_name not in df_output .columns :
1142
- df_output = df_output .reset_index ()
1162
+ wide_value_vars = [c for c in args ["wide_cols" ] if c not in wide_id_vars ]
1163
+ del args ["wide_cols" ]
1143
1164
df_output = df_output .melt (
1144
- id_vars = wide_id_vars , var_name = var_name , value_name = "_value_"
1165
+ id_vars = wide_id_vars ,
1166
+ value_vars = wide_value_vars ,
1167
+ var_name = var_name ,
1168
+ value_name = "_value_" ,
1145
1169
)
1146
1170
df_output [var_name ] = df_output [var_name ].astype (str )
1147
1171
args ["orientation" ] = args .get ("orientation" , None ) or "v"
0 commit comments