Skip to content

Commit fb914e2

Browse files
swap getsizeof for more relevant values (microsoft#5371)
* swap getsizeof for more relevant values * change size name to count
1 parent ebbf1a7 commit fb914e2

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

news/1 Enhancements/5368.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Swap getsizeof size value for something more sensible in the variable explorer

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
"LanguageService.reloadVSCodeIfSeachPathHasChanged": "Search paths have changed for this Python interpreter. Please reload the extension to ensure that the IntelliSense works correctly",
221221
"DataScience.variableExplorerNameColumn": "Name",
222222
"DataScience.variableExplorerTypeColumn": "Type",
223-
"DataScience.variableExplorerSizeColumn": "Size",
223+
"DataScience.variableExplorerSizeColumn": "Count",
224224
"DataScience.variableExplorerValueColumn": "Value",
225225
"DataScience.showDataExplorerTooltip": "Show variable in data explorer.",
226226
"DataScience.dataExplorerInvalidVariableFormat": "'{0}' is not an active variable.",

pythonFiles/datascience/getJupyterVariableValue.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
_VSCODE_evalResult = eval(_VSCODE_targetVariable['name'])
99

1010
# Find shape and count if available
11-
if _VSCODE_targetVariable['type'] in ['ndarray','DataFrame','Series']:
11+
if (hasattr(_VSCODE_evalResult, 'shape')):
1212
_VSCODE_targetVariable['shape'] = str(_VSCODE_evalResult.shape)
1313

14-
if _VSCODE_targetVariable['type'] in ['tuple', 'str', 'dict', 'list', 'set', 'ndarray','DataFrame','Series']:
14+
if (hasattr(_VSCODE_evalResult, '__len__')):
1515
_VSCODE_targetVariable['count'] = len(_VSCODE_evalResult)
1616

1717
# Get the string of the eval result, truncate it as it could be far too long

src/datascience-ui/history-react/variableExplorer.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class VariableExplorer extends React.Component<IVariableExplorerProps, IV
5353
const columns = [
5454
{key: 'name', name: getLocString('DataScience.variableExplorerNameColumn', 'Name'), type: 'string', width: 120, formatter: <VariableExplorerCellFormatter cellStyle={CellStyle.variable} />},
5555
{key: 'type', name: getLocString('DataScience.variableExplorerTypeColumn', 'Type'), type: 'string', width: 120},
56-
{key: 'size', name: getLocString('DataScience.variableExplorerSizeColumn', 'Size'), type: 'number', width: 120, formatter: <VariableExplorerCellFormatter cellStyle={CellStyle.numeric} />},
56+
{key: 'size', name: getLocString('DataScience.variableExplorerSizeColumn', 'Count'), type: 'string', width: 120, formatter: <VariableExplorerCellFormatter cellStyle={CellStyle.numeric} />},
5757
{key: 'value', name: getLocString('DataScience.variableExplorerValueColumn', 'Value'), type: 'string', width: 300},
5858
{key: 'buttons', name: '', type: 'boolean', width: 34, formatter: <VariableExplorerButtonCellFormatter showDataExplorer={this.props.showDataExplorer} baseTheme={this.props.baseTheme} /> }
5959
];
@@ -125,7 +125,7 @@ export class VariableExplorer extends React.Component<IVariableExplorerProps, IV
125125
// Help to keep us independent of main history window state if we choose to break out the variable explorer
126126
public newVariablesData(newVariables: IJupyterVariable[]) {
127127
const newGridRows = newVariables.map(newVar => {
128-
return { buttons: {name: newVar.name, supportsDataExplorer: newVar.supportsDataExplorer}, name: newVar.name, type: newVar.type, size: newVar.size, value: getLocString('DataScience.variableLoadingValue', 'Loading...')};
128+
return { buttons: {name: newVar.name, supportsDataExplorer: newVar.supportsDataExplorer}, name: newVar.name, type: newVar.type, size: '', value: getLocString('DataScience.variableLoadingValue', 'Loading...')};
129129
});
130130

131131
this.setState({ gridRows: newGridRows});
@@ -136,7 +136,19 @@ export class VariableExplorer extends React.Component<IVariableExplorerProps, IV
136136
const newGridRows = this.state.gridRows.slice();
137137
for (let i = 0; i < newGridRows.length; i = i + 1) {
138138
if (newGridRows[i].name === newVariable.name) {
139-
const newGridRow = {...newGridRows[i], value: newVariable.value};
139+
140+
// For object with shape, use that for size
141+
// for object with length use that for size
142+
// If it doesn't have either, then just leave it out
143+
let newSize = '';
144+
if (newVariable.shape && newVariable.shape !== '') {
145+
newSize = newVariable.shape;
146+
} else if (newVariable.count) {
147+
newSize = newVariable.count.toString();
148+
}
149+
150+
const newGridRow = {...newGridRows[i], value: newVariable.value, size: newSize};
151+
140152
newGridRows[i] = newGridRow;
141153
}
142154
}

src/test/datascience/variableexplorer.functional.test.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@ function verifyRow(rowWrapper: ReactWrapper<any, Readonly<{}>, React.Component>,
268268

269269
verifyCell(rowCells.at(0), targetVariable.name, targetVariable.name);
270270
verifyCell(rowCells.at(1), targetVariable.type, targetVariable.name);
271+
272+
if (targetVariable.shape && targetVariable.shape !== '') {
273+
verifyCell(rowCells.at(2), targetVariable.shape, targetVariable.name);
274+
} else if (targetVariable.count) {
275+
verifyCell(rowCells.at(2), targetVariable.count.toString(), targetVariable.name);
276+
}
277+
271278
verifyCell(rowCells.at(3), targetVariable.value ? targetVariable.value : '', targetVariable.name);
272279
}
273280

0 commit comments

Comments
 (0)