Skip to content

Commit b32bf74

Browse files
committed
gbd interactive command
1 parent 3d77b0d commit b32bf74

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

gbd.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ 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+
import IPython
90+
IPython.embed(header ="GBD data is available as `data`", colors="neutral")
91+
8792
def cli_set(api: GBD, args):
8893
hashes = api.query(args.query, args.hashes)['hash'].tolist()
8994
if args.create:
@@ -187,6 +192,17 @@ def main():
187192
parser_get.add_argument('-H', '--header', action='store_true', help='Include header information in output')
188193
parser_get.set_defaults(func=cli_get)
189194

195+
# GBD INTERACTIVE $QUERY
196+
parser_interactive = subparsers.add_parser('interactive', help='Get data by query (or hash-list via stdin) and open interactive Python prompt')
197+
add_query_and_hashes_arguments(parser_interactive)
198+
parser_interactive.add_argument('-r', '--resolve', help='List of feature names to resolve against', nargs='+', default=[])
199+
parser_interactive.add_argument('-c', '--collapse', default='group_concat',
200+
choices=['group_concat', 'min', 'max', 'avg', 'count', 'sum', 'none'],
201+
help='Specify a function for the handling of multiple feature values')
202+
parser_interactive.add_argument('-g', '--group_by', default=None, help='Group by the specified feature as the key, rather than by the primary key')
203+
parser_interactive.add_argument('--join-type', help='Join Type: treatment of missing values', choices=['INNER', 'OUTER', 'LEFT'], default="LEFT")
204+
parser_interactive.set_defaults(func=cli_interactive)
205+
190206
# GBD SET
191207
parser_set = subparsers.add_parser('set', help='Set specified attribute-value for query result')
192208
parser_set.add_argument('assign', type=key_value_type, help='key=value')

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
'pandas',
2828
'waitress',
2929
'pebble',
30-
'gbdc'
30+
'gbdc',
31+
'IPython'
3132
],
3233
install_obsoletes=['global-benchmark-database-tool'],
3334
classifiers=[

0 commit comments

Comments
 (0)