22import json as _VSCODE_json
33import pandas as _VSCODE_pd
44
5+ # _VSCode_sub_supportsDataExplorer will contain our list of data explorer supported types
6+ _VSCode_supportsDataExplorer = _VSCode_sub_supportsDataExplorer
7+
58# In IJupyterVariables.getValue this '_VSCode_JupyterTestValue' will be replaced with the json stringified value of the target variable
69# Indexes off of _VSCODE_targetVariable need to index types that are part of IJupyterVariable
710_VSCODE_targetVariable = _VSCODE_json .loads ('_VSCode_JupyterTestValue' )
8- _VSCODE_evalResult = eval (_VSCODE_targetVariable ['name' ])
911
10- # First list out the columns of the data frame (assuming it is one for now)
11- _VSCODE_columnTypes = []
12- _VSCODE_columnNames = []
13- if _VSCODE_targetVariable ['type' ] == 'list' :
14- _VSCODE_columnTypes = ['string' ] # Might be able to be more specific here?
15- _VSCODE_columnNames = ['_VSCode_JupyterValuesColumn' ]
16- elif _VSCODE_targetVariable ['type' ] == 'Series' :
17- _VSCODE_evalResult = _VSCODE_pd .Series .to_frame (_VSCODE_evalResult )
18- _VSCODE_columnTypes = list (_VSCODE_evalResult .dtypes )
19- _VSCODE_columnNames = list (_VSCODE_evalResult )
20- elif _VSCODE_targetVariable ['type' ] == 'dict' :
21- _VSCODE_evalResult = _VSCODE_pd .Series (_VSCODE_evalResult )
22- _VSCODE_evalResult = _VSCODE_pd .Series .to_frame (_VSCODE_evalResult )
23- _VSCODE_columnTypes = list (_VSCODE_evalResult .dtypes )
24- _VSCODE_columnNames = list (_VSCODE_evalResult )
25- elif _VSCODE_targetVariable ['type' ] == 'ndarray' :
26- _VSCODE_evalResult = _VSCODE_pd .Series (_VSCODE_evalResult )
27- _VSCODE_evalResult = _VSCODE_pd .Series .to_frame (_VSCODE_evalResult )
28- _VSCODE_columnTypes = list (_VSCODE_evalResult .dtypes )
29- _VSCODE_columnNames = list (_VSCODE_evalResult )
30- elif _VSCODE_targetVariable ['type' ] == 'DataFrame' :
31- _VSCODE_columnTypes = list (_VSCODE_evalResult .dtypes )
32- _VSCODE_columnNames = list (_VSCODE_evalResult )
12+ # First check to see if we are a supported type, this prevents us from adding types that are not supported
13+ # and also keeps our types in sync with what the variable explorer says that we support
14+ if _VSCODE_targetVariable ['type' ] not in _VSCode_supportsDataExplorer :
15+ del _VSCode_supportsDataExplorer
16+ print (_VSCODE_json .dumps (_VSCODE_targetVariable ))
17+ del _VSCODE_targetVariable
18+ else :
19+ del _VSCode_supportsDataExplorer
20+ _VSCODE_evalResult = eval (_VSCODE_targetVariable ['name' ])
21+
22+ # First list out the columns of the data frame (assuming it is one for now)
23+ _VSCODE_columnTypes = []
24+ _VSCODE_columnNames = []
25+ if _VSCODE_targetVariable ['type' ] == 'list' :
26+ _VSCODE_columnTypes = ['string' ] # Might be able to be more specific here?
27+ _VSCODE_columnNames = ['_VSCode_JupyterValuesColumn' ]
28+ elif _VSCODE_targetVariable ['type' ] == 'Series' :
29+ _VSCODE_evalResult = _VSCODE_pd .Series .to_frame (_VSCODE_evalResult )
30+ _VSCODE_columnTypes = list (_VSCODE_evalResult .dtypes )
31+ _VSCODE_columnNames = list (_VSCODE_evalResult )
32+ elif _VSCODE_targetVariable ['type' ] == 'dict' :
33+ _VSCODE_evalResult = _VSCODE_pd .Series (_VSCODE_evalResult )
34+ _VSCODE_evalResult = _VSCODE_pd .Series .to_frame (_VSCODE_evalResult )
35+ _VSCODE_columnTypes = list (_VSCODE_evalResult .dtypes )
36+ _VSCODE_columnNames = list (_VSCODE_evalResult )
37+ elif _VSCODE_targetVariable ['type' ] == 'ndarray' :
38+ _VSCODE_evalResult = _VSCODE_pd .Series (_VSCODE_evalResult )
39+ _VSCODE_evalResult = _VSCODE_pd .Series .to_frame (_VSCODE_evalResult )
40+ _VSCODE_columnTypes = list (_VSCODE_evalResult .dtypes )
41+ _VSCODE_columnNames = list (_VSCODE_evalResult )
42+ elif _VSCODE_targetVariable ['type' ] == 'DataFrame' :
43+ _VSCODE_columnTypes = list (_VSCODE_evalResult .dtypes )
44+ _VSCODE_columnNames = list (_VSCODE_evalResult )
3345
34- # Make sure we have an index column (see code in getJupyterVariableDataFrameRows.py)
35- if 'index' not in _VSCODE_columnNames :
36- _VSCODE_columnNames .insert (0 , 'index' )
37- _VSCODE_columnTypes .insert (0 , 'int64' )
46+ # Make sure we have an index column (see code in getJupyterVariableDataFrameRows.py)
47+ if 'index' not in _VSCODE_columnNames :
48+ _VSCODE_columnNames .insert (0 , 'index' )
49+ _VSCODE_columnTypes .insert (0 , 'int64' )
3850
39- # Then loop and generate our output json
40- _VSCODE_columns = []
41- for _VSCODE_n in range (0 , len (_VSCODE_columnNames )):
42- _VSCODE_column_name = _VSCODE_columnNames [_VSCODE_n ]
43- _VSCODE_column_type = _VSCODE_columnTypes [_VSCODE_n ]
44- _VSCODE_colobj = {}
45- _VSCODE_colobj ['key' ] = _VSCODE_column_name
46- _VSCODE_colobj ['name' ] = _VSCODE_column_name
47- _VSCODE_colobj ['type' ] = str (_VSCODE_column_type )
48- _VSCODE_columns .append (_VSCODE_colobj )
51+ # Then loop and generate our output json
52+ _VSCODE_columns = []
53+ for _VSCODE_n in range (0 , len (_VSCODE_columnNames )):
54+ _VSCODE_column_name = _VSCODE_columnNames [_VSCODE_n ]
55+ _VSCODE_column_type = _VSCODE_columnTypes [_VSCODE_n ]
56+ _VSCODE_colobj = {}
57+ _VSCODE_colobj ['key' ] = _VSCODE_column_name
58+ _VSCODE_colobj ['name' ] = _VSCODE_column_name
59+ _VSCODE_colobj ['type' ] = str (_VSCODE_column_type )
60+ _VSCODE_columns .append (_VSCODE_colobj )
4961
50- del _VSCODE_columnNames
51- del _VSCODE_columnTypes
62+ del _VSCODE_columnNames
63+ del _VSCODE_columnTypes
5264
53- # Save this in our target
54- _VSCODE_targetVariable ['columns' ] = _VSCODE_columns
55- del _VSCODE_columns
65+ # Save this in our target
66+ _VSCODE_targetVariable ['columns' ] = _VSCODE_columns
67+ del _VSCODE_columns
5668
57- # Figure out shape if not already there. Use the shape to compute the row count
58- if (hasattr (_VSCODE_evalResult , "shape" )):
59- _VSCODE_targetVariable ['rowCount' ] = _VSCODE_evalResult .shape [0 ]
60- elif _VSCODE_targetVariable ['type' ] == 'list' :
61- _VSCODE_targetVariable ['rowCount' ] = len (_VSCODE_evalResult )
62- else :
63- _VSCODE_targetVariable ['rowCount' ] = 0
69+ # Figure out shape if not already there. Use the shape to compute the row count
70+ if (hasattr (_VSCODE_evalResult , "shape" )):
71+ _VSCODE_targetVariable ['rowCount' ] = _VSCODE_evalResult .shape [0 ]
72+ elif _VSCODE_targetVariable ['type' ] == 'list' :
73+ _VSCODE_targetVariable ['rowCount' ] = len (_VSCODE_evalResult )
74+ else :
75+ _VSCODE_targetVariable ['rowCount' ] = 0
6476
65- # Transform this back into a string
66- print (_VSCODE_json .dumps (_VSCODE_targetVariable ))
77+ # Transform this back into a string
78+ print (_VSCODE_json .dumps (_VSCODE_targetVariable ))
79+ del _VSCODE_targetVariable
0 commit comments