Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1 Enhancements/5368.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Swap getsizeof size value for something more sensible in the variable explorer
2 changes: 1 addition & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
"LanguageService.reloadVSCodeIfSeachPathHasChanged": "Search paths have changed for this Python interpreter. Please reload the extension to ensure that the IntelliSense works correctly",
"DataScience.variableExplorerNameColumn": "Name",
"DataScience.variableExplorerTypeColumn": "Type",
"DataScience.variableExplorerSizeColumn": "Size",
"DataScience.variableExplorerSizeColumn": "Count",
"DataScience.variableExplorerValueColumn": "Value",
"DataScience.showDataExplorerTooltip": "Show variable in data explorer.",
"DataScience.dataExplorerInvalidVariableFormat": "'{0}' is not an active variable.",
Expand Down
4 changes: 2 additions & 2 deletions pythonFiles/datascience/getJupyterVariableValue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
_VSCODE_evalResult = eval(_VSCODE_targetVariable['name'])

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

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

# Get the string of the eval result, truncate it as it could be far too long
Expand Down
18 changes: 15 additions & 3 deletions src/datascience-ui/history-react/variableExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class VariableExplorer extends React.Component<IVariableExplorerProps, IV
const columns = [
{key: 'name', name: getLocString('DataScience.variableExplorerNameColumn', 'Name'), type: 'string', width: 120, formatter: <VariableExplorerCellFormatter cellStyle={CellStyle.variable} />},
{key: 'type', name: getLocString('DataScience.variableExplorerTypeColumn', 'Type'), type: 'string', width: 120},
{key: 'size', name: getLocString('DataScience.variableExplorerSizeColumn', 'Size'), type: 'number', width: 120, formatter: <VariableExplorerCellFormatter cellStyle={CellStyle.numeric} />},
{key: 'size', name: getLocString('DataScience.variableExplorerSizeColumn', 'Count'), type: 'string', width: 120, formatter: <VariableExplorerCellFormatter cellStyle={CellStyle.numeric} />},
{key: 'value', name: getLocString('DataScience.variableExplorerValueColumn', 'Value'), type: 'string', width: 300},
{key: 'buttons', name: '', type: 'boolean', width: 34, formatter: <VariableExplorerButtonCellFormatter showDataExplorer={this.props.showDataExplorer} baseTheme={this.props.baseTheme} /> }
];
Expand Down Expand Up @@ -125,7 +125,7 @@ export class VariableExplorer extends React.Component<IVariableExplorerProps, IV
// Help to keep us independent of main history window state if we choose to break out the variable explorer
public newVariablesData(newVariables: IJupyterVariable[]) {
const newGridRows = newVariables.map(newVar => {
return { buttons: {name: newVar.name, supportsDataExplorer: newVar.supportsDataExplorer}, name: newVar.name, type: newVar.type, size: newVar.size, value: getLocString('DataScience.variableLoadingValue', 'Loading...')};
return { buttons: {name: newVar.name, supportsDataExplorer: newVar.supportsDataExplorer}, name: newVar.name, type: newVar.type, size: '', value: getLocString('DataScience.variableLoadingValue', 'Loading...')};
});

this.setState({ gridRows: newGridRows});
Expand All @@ -136,7 +136,19 @@ export class VariableExplorer extends React.Component<IVariableExplorerProps, IV
const newGridRows = this.state.gridRows.slice();
for (let i = 0; i < newGridRows.length; i = i + 1) {
if (newGridRows[i].name === newVariable.name) {
const newGridRow = {...newGridRows[i], value: newVariable.value};

// For object with shape, use that for size
// for object with length use that for size
// If it doesn't have either, then just leave it out
let newSize = '';
if (newVariable.shape && newVariable.shape !== '') {
newSize = newVariable.shape;
} else if (newVariable.count) {
newSize = newVariable.count.toString();
}

const newGridRow = {...newGridRows[i], value: newVariable.value, size: newSize};

newGridRows[i] = newGridRow;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/datascience/variableexplorer.functional.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ function verifyRow(rowWrapper: ReactWrapper<any, Readonly<{}>, React.Component>,

verifyCell(rowCells.at(0), targetVariable.name, targetVariable.name);
verifyCell(rowCells.at(1), targetVariable.type, targetVariable.name);

if (targetVariable.shape && targetVariable.shape !== '') {
verifyCell(rowCells.at(2), targetVariable.shape, targetVariable.name);
} else if (targetVariable.count) {
verifyCell(rowCells.at(2), targetVariable.count.toString(), targetVariable.name);
}

verifyCell(rowCells.at(3), targetVariable.value ? targetVariable.value : '', targetVariable.name);
}

Expand Down