@@ -84,6 +84,15 @@ def cli_get(api: GBD, args):
8484 for index , row in df .iterrows ():
8585 print (args .delimiter .join ([ item or "[None]" for item in row .to_list () ]))
8686
87+ def cli_interactive (api : GBD , args ):
88+ data = api .query (args .query , args .hashes , args .resolve , args .collapse , args .group_by , args .join_type )
89+ if args .group_by :
90+ data .set_index (args .group_by , inplace = True )
91+ else :
92+ data .set_index ('hash' , inplace = True )
93+ import IPython
94+ IPython .embed (header = "GBD data is available as `data`" , colors = "neutral" )
95+
8796def cli_set (api : GBD , args ):
8897 hashes = api .query (args .query , args .hashes )['hash' ].tolist ()
8998 if args .create :
@@ -187,6 +196,17 @@ def main():
187196 parser_get .add_argument ('-H' , '--header' , action = 'store_true' , help = 'Include header information in output' )
188197 parser_get .set_defaults (func = cli_get )
189198
199+ # GBD INTERACTIVE $QUERY
200+ parser_interactive = subparsers .add_parser ('interactive' , help = 'Get data by query (or hash-list via stdin) and open interactive Python prompt' )
201+ add_query_and_hashes_arguments (parser_interactive )
202+ parser_interactive .add_argument ('-r' , '--resolve' , help = 'List of feature names to resolve against' , nargs = '+' , default = [])
203+ parser_interactive .add_argument ('-c' , '--collapse' , default = 'group_concat' ,
204+ choices = ['group_concat' , 'min' , 'max' , 'avg' , 'count' , 'sum' , 'none' ],
205+ help = 'Specify a function for the handling of multiple feature values' )
206+ parser_interactive .add_argument ('-g' , '--group_by' , default = None , help = 'Group by the specified feature as the key, rather than by the primary key' )
207+ parser_interactive .add_argument ('--join-type' , help = 'Join Type: treatment of missing values' , choices = ['INNER' , 'OUTER' , 'LEFT' ], default = "LEFT" )
208+ parser_interactive .set_defaults (func = cli_interactive )
209+
190210 # GBD SET
191211 parser_set = subparsers .add_parser ('set' , help = 'Set specified attribute-value for query result' )
192212 parser_set .add_argument ('assign' , type = key_value_type , help = 'key=value' )
0 commit comments