minimal adjustments
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-python / pythonFiles / datascience / getJupyterVariableValue.py
1 # Query Jupyter server for the value of a variable
2 import json
3 _VSCODE_max_len = 200
4 # In IJupyterVariables.getValue this '_VSCode_JupyterTestValue' will be replaced with the json stringified value of the target variable
5 # Indexes off of _VSCODE_targetVariable need to index types that are part of IJupyterVariable
6 _VSCODE_targetVariable = json.loads('_VSCode_JupyterTestValue')
7
8 _VSCODE_evalResult = eval(_VSCODE_targetVariable['name'])
9
10 # Find shape and count if available
11 if _VSCODE_targetVariable['type'] in ['ndarray','DataFrame','Series']:
12     _VSCODE_targetVariable['shape'] = str(_VSCODE_evalResult.shape)
13
14 if _VSCODE_targetVariable['type'] in ['tuple', 'str', 'dict', 'list', 'set', 'ndarray','DataFrame','Series']:
15     _VSCODE_targetVariable['count'] = len(_VSCODE_evalResult)
16
17 # Get the string of the eval result, truncate it as it could be far too long
18 _VSCODE_targetValue = str(_VSCODE_evalResult)
19 if len(_VSCODE_targetValue) > _VSCODE_max_len:
20     _VSCODE_targetVariable['truncated'] = True
21     _VSCODE_targetVariable['value'] = _VSCODE_targetValue[:_VSCODE_max_len]
22 else:
23     _VSCODE_targetVariable['value'] = _VSCODE_targetValue
24
25 print(json.dumps(_VSCODE_targetVariable))