.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-python / pythonFiles / datascience / getJupyterVariableValue.py
diff --git a/.config/coc/extensions/node_modules/coc-python/pythonFiles/datascience/getJupyterVariableValue.py b/.config/coc/extensions/node_modules/coc-python/pythonFiles/datascience/getJupyterVariableValue.py
new file mode 100644 (file)
index 0000000..1b4e8b3
--- /dev/null
@@ -0,0 +1,25 @@
+# Query Jupyter server for the value of a variable
+import json
+_VSCODE_max_len = 200
+# In IJupyterVariables.getValue this '_VSCode_JupyterTestValue' will be replaced with the json stringified value of the target variable
+# Indexes off of _VSCODE_targetVariable need to index types that are part of IJupyterVariable
+_VSCODE_targetVariable = json.loads('_VSCode_JupyterTestValue')
+
+_VSCODE_evalResult = eval(_VSCODE_targetVariable['name'])
+
+# Find shape and count if available
+if _VSCODE_targetVariable['type'] in ['ndarray','DataFrame','Series']:
+    _VSCODE_targetVariable['shape'] = str(_VSCODE_evalResult.shape)
+
+if _VSCODE_targetVariable['type'] in ['tuple', 'str', 'dict', 'list', 'set', 'ndarray','DataFrame','Series']:
+    _VSCODE_targetVariable['count'] = len(_VSCODE_evalResult)
+
+# Get the string of the eval result, truncate it as it could be far too long
+_VSCODE_targetValue = str(_VSCODE_evalResult)
+if len(_VSCODE_targetValue) > _VSCODE_max_len:
+    _VSCODE_targetVariable['truncated'] = True
+    _VSCODE_targetVariable['value'] = _VSCODE_targetValue[:_VSCODE_max_len]
+else:
+    _VSCODE_targetVariable['value'] = _VSCODE_targetValue
+
+print(json.dumps(_VSCODE_targetVariable))
\ No newline at end of file