Skip to content

Commit a49cebf

Browse files
authored
Fix data viewer issues (microsoft#5405)
1 parent dada212 commit a49cebf

File tree

12 files changed

+81
-31
lines changed

12 files changed

+81
-31
lines changed

news/2 Fixes/5278.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Filtered rows shows 'fetching' instead of No rows.

news/2 Fixes/5395.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Multi-dimensional arrays don't open in the data viewer.

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@
226226
"DataScience.dataExplorerInvalidVariableFormat": "'{0}' is not an active variable.",
227227
"DataScience.jupyterGetVariablesExecutionError": "Failure during variable extraction:\r\n{0}",
228228
"DataScience.loadingMessage": "loading ...",
229-
"DataScience.noRowsInDataViewer": "Fetching data ...",
229+
"DataScience.fetchingDataViewer": "Fetching data ...",
230+
"DataScience.noRowsInDataViewer": "No rows match current filter",
230231
"DataScience.pandasTooOldForViewingFormat": "Python package 'pandas' is version {0}. Version 0.20 or greater is required for viewing data.",
231232
"DataScience.pandasRequiredForViewing": "Python package 'pandas' is required for viewing data.",
232233
"DataScience.valuesColumn": "values",

pythonFiles/datascience/getJupyterVariableDataFrameInfo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
_VSCODE_columnTypes = list(_VSCODE_evalResult.dtypes)
3636
_VSCODE_columnNames = list(_VSCODE_evalResult)
3737
elif _VSCODE_targetVariable['type'] == 'ndarray':
38-
_VSCODE_evalResult = _VSCODE_pd.Series(_VSCODE_evalResult)
39-
_VSCODE_evalResult = _VSCODE_pd.Series.to_frame(_VSCODE_evalResult)
38+
_VSCODE_evalResult = _VSCODE_pd.DataFrame(_VSCODE_evalResult)
4039
_VSCODE_columnTypes = list(_VSCODE_evalResult.dtypes)
4140
_VSCODE_columnNames = list(_VSCODE_evalResult)
4241
elif _VSCODE_targetVariable['type'] == 'DataFrame':

pythonFiles/datascience/getJupyterVariableDataFrameRows.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
_VSCODE_evalResult = _VSCODE_pd.Series(_VSCODE_evalResult)
2424
_VSCODE_df = _VSCODE_pd.Series.to_frame(_VSCODE_evalResult)
2525
elif _VSCODE_targetVariable['type'] == 'ndarray':
26-
_VSCODE_evalResult = _VSCODE_pd.Series(_VSCODE_evalResult)
27-
_VSCODE_df = _VSCODE_pd.Series.to_frame(_VSCODE_evalResult)
26+
_VSCODE_df = _VSCODE_pd.DataFrame(_VSCODE_evalResult)
2827
# If not a known type, then just let pandas handle it.
2928
elif not (hasattr(_VSCODE_df, 'iloc')):
3029
_VSCODE_df = _VSCODE_pd.DataFrame(_VSCODE_evalResult)

pythonFiles/tests/ipython/test_variables.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ def test_dataframe_info(capsys):
4949
ls = list([10, 20, 30, 40])
5050
df = pd.DataFrame(ls)
5151
se = pd.Series(ls)
52-
np = np.array(ls)
52+
np1 = np.array(ls)
53+
np2 = np.array([[1, 2, 3], [4, 5, 6]])
5354
obj = {}
5455
''')
5556
vars = get_variables(capsys)
5657
df = get_variable_value(vars, 'df', capsys)
5758
se = get_variable_value(vars, 'se', capsys)
58-
np = get_variable_value(vars, 'np', capsys)
59+
np = get_variable_value(vars, 'np1', capsys)
60+
np2 = get_variable_value(vars, 'np2', capsys)
5961
ls = get_variable_value(vars, 'ls', capsys)
6062
obj = get_variable_value(vars, 'obj', capsys)
6163
assert df
@@ -65,8 +67,9 @@ def test_dataframe_info(capsys):
6567
assert obj
6668
verify_dataframe_info(vars, 'df', capsys, True)
6769
verify_dataframe_info(vars, 'se', capsys, True)
68-
verify_dataframe_info(vars, 'np', capsys, True)
70+
verify_dataframe_info(vars, 'np1', capsys, True)
6971
verify_dataframe_info(vars, 'ls', capsys, True)
72+
verify_dataframe_info(vars, 'np2', capsys, True)
7073
verify_dataframe_info(vars, 'obj', capsys, False)
7174

7275
def verify_dataframe_info(vars, name, capsys, hasInfo):
@@ -96,6 +99,27 @@ def test_dataframe_rows(capsys):
9699
rows = get_data_frame_rows(info, 100, 200, capsys)
97100
assert rows
98101
assert rows['data'][0]['+h2'] == 'Fy3 W[pMT['
102+
get_ipython().run_cell('''
103+
import pandas as pd
104+
import numpy as np
105+
ls = list([10, 20, 30, 40])
106+
df = pd.DataFrame(ls)
107+
se = pd.Series(ls)
108+
np1 = np.array(ls)
109+
np2 = np.array([[1, 2, 3], [4, 5, 6]])
110+
obj = {}
111+
''')
112+
vars = get_variables(capsys)
113+
np2 = get_variable_value(vars, 'np2', capsys)
114+
assert np2
115+
info = get_data_frame_info(vars, 'np2', capsys)
116+
assert 'rowCount' in info
117+
assert info['rowCount'] == 2
118+
rows = get_data_frame_rows(info, 0, 2, capsys)
119+
assert rows
120+
assert rows['data'][0]
121+
122+
99123

100124

101125

src/client/common/utils/localize.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ export namespace DataScience {
160160
export const pythonInteractiveCreateFailed = localize('DataScience.pythonInteractiveCreateFailed', 'Failure to create a \'Python Interactive\' window. Try reinstalling the Python extension.');
161161
export const jupyterGetVariablesExecutionError = localize('DataScience.jupyterGetVariablesExecutionError', 'Failure during variable extraction: \r\n{0}');
162162
export const loadingMessage = localize('DataScience.loadingMessage', 'loading ...');
163-
export const noRowsInDataViewer = localize('DataScience.noRowsInDataViewer', 'Fetching data ...');
163+
export const fetchingDataViewer = localize('DataScience.fetchingDataViewer', 'Fetching data ...');
164+
export const noRowsInDataViewer = localize('DataScience.noRowsInDataViewer', 'No rows match current filter');
164165
export const pandasTooOldForViewingFormat = localize('DataScience.pandasTooOldForViewingFormat', 'Python package \'pandas\' is version {0}. Version 0.20 or greater is required for viewing data.');
165166
export const pandasRequiredForViewing = localize('DataScience.pandasRequiredForViewing', 'Python package \'pandas\' is required for viewing data.');
166167
export const valuesColumn = localize('DataScience.valuesColumn', 'values');
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
.progress-bar {
2-
margin:2px;
3-
text-align: center;
4-
}
5-
6-
.progress-container {
7-
padding: 20px;
8-
text-align:center;
9-
}

src/datascience-ui/data-explorer/emptyRowsView.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,14 @@ import * as React from 'react';
77
import { getLocString } from '../react-common/locReactSide';
88

99
export interface IEmptyRowsProps {
10-
total: number;
11-
current: number;
1210
}
1311

14-
export const EmptyRowsView = (props: IEmptyRowsProps) => {
15-
const percent = props.current / props.total * 100;
16-
const percentText = `${Math.round(percent)}%`;
17-
const style: React.CSSProperties = {
18-
width: percentText
19-
};
20-
const message = getLocString('DataScience.noRowsInDataViewer', 'Fetching data ...');
12+
export const EmptyRows = (_props: IEmptyRowsProps) => {
13+
const message = getLocString('DataScience.noRowsInDataViewer', 'No rows match current filter');
2114

2215
return (
23-
<div className='progress-container'>
16+
<div className='container'>
2417
{message}
25-
<div className='progress-bar' style={style}>{percentText}</div>
2618
</div>
2719
);
2820
};

src/datascience-ui/data-explorer/mainPanel.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import { IJupyterVariable } from '../../client/datascience/types';
2121
import { IMessageHandler, PostOffice } from '../react-common/postOffice';
2222
import { StyleInjector } from '../react-common/styleInjector';
2323
import { CellFormatter } from './cellFormatter';
24-
import { EmptyRowsView } from './emptyRowsView';
24+
import { EmptyRows } from './emptyRowsView';
25+
import { ProgressBar } from './progressBar';
2526
import { generateTestData } from './testData';
2627

2728
import 'bootstrap/dist/css/bootstrap.css';
@@ -118,7 +119,10 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
118119

119120
public componentDidUpdate() {
120121
// Rebind our empty rows view to our new state.
121-
this.emptyRows = EmptyRowsView.bind(this, {current: this.state.fetchedRowCount, total: this.state.actualRowCount});
122+
this.emptyRows = this.state.fetchedRowCount === this.state.actualRowCount ?
123+
EmptyRows.bind(this, {current: this.state.fetchedRowCount, total: this.state.actualRowCount}) :
124+
ProgressBar.bind(this, {current: this.state.fetchedRowCount, total: this.state.actualRowCount});
125+
122126
this.getEmptyRows = (_props: any) => {
123127
return this.emptyRows ? this.emptyRows() : <div/>;
124128
};

0 commit comments

Comments
 (0)