Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data viewer issues #5405

Merged
merged 1 commit into from
Apr 22, 2019
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/2 Fixes/5278.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Filtered rows shows 'fetching' instead of No rows.
1 change: 1 addition & 0 deletions news/2 Fixes/5395.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Multi-dimensional arrays don't open in the data viewer.
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@
"DataScience.dataExplorerInvalidVariableFormat": "'{0}' is not an active variable.",
"DataScience.jupyterGetVariablesExecutionError": "Failure during variable extraction:\r\n{0}",
"DataScience.loadingMessage": "loading ...",
"DataScience.noRowsInDataViewer": "Fetching data ...",
"DataScience.fetchingDataViewer": "Fetching data ...",
"DataScience.noRowsInDataViewer": "No rows match current filter",
"DataScience.pandasTooOldForViewingFormat": "Python package 'pandas' is version {0}. Version 0.20 or greater is required for viewing data.",
"DataScience.pandasRequiredForViewing": "Python package 'pandas' is required for viewing data.",
"DataScience.valuesColumn": "values",
Expand Down
3 changes: 1 addition & 2 deletions pythonFiles/datascience/getJupyterVariableDataFrameInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
_VSCODE_columnTypes = list(_VSCODE_evalResult.dtypes)
_VSCODE_columnNames = list(_VSCODE_evalResult)
elif _VSCODE_targetVariable['type'] == 'ndarray':
_VSCODE_evalResult = _VSCODE_pd.Series(_VSCODE_evalResult)
_VSCODE_evalResult = _VSCODE_pd.Series.to_frame(_VSCODE_evalResult)
_VSCODE_evalResult = _VSCODE_pd.DataFrame(_VSCODE_evalResult)
_VSCODE_columnTypes = list(_VSCODE_evalResult.dtypes)
_VSCODE_columnNames = list(_VSCODE_evalResult)
elif _VSCODE_targetVariable['type'] == 'DataFrame':
Expand Down
3 changes: 1 addition & 2 deletions pythonFiles/datascience/getJupyterVariableDataFrameRows.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
_VSCODE_evalResult = _VSCODE_pd.Series(_VSCODE_evalResult)
_VSCODE_df = _VSCODE_pd.Series.to_frame(_VSCODE_evalResult)
elif _VSCODE_targetVariable['type'] == 'ndarray':
_VSCODE_evalResult = _VSCODE_pd.Series(_VSCODE_evalResult)
_VSCODE_df = _VSCODE_pd.Series.to_frame(_VSCODE_evalResult)
_VSCODE_df = _VSCODE_pd.DataFrame(_VSCODE_evalResult)
# If not a known type, then just let pandas handle it.
elif not (hasattr(_VSCODE_df, 'iloc')):
_VSCODE_df = _VSCODE_pd.DataFrame(_VSCODE_evalResult)
Expand Down
30 changes: 27 additions & 3 deletions pythonFiles/tests/ipython/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ def test_dataframe_info(capsys):
ls = list([10, 20, 30, 40])
df = pd.DataFrame(ls)
se = pd.Series(ls)
np = np.array(ls)
np1 = np.array(ls)
np2 = np.array([[1, 2, 3], [4, 5, 6]])
obj = {}
''')
vars = get_variables(capsys)
df = get_variable_value(vars, 'df', capsys)
se = get_variable_value(vars, 'se', capsys)
np = get_variable_value(vars, 'np', capsys)
np = get_variable_value(vars, 'np1', capsys)
np2 = get_variable_value(vars, 'np2', capsys)
ls = get_variable_value(vars, 'ls', capsys)
obj = get_variable_value(vars, 'obj', capsys)
assert df
Expand All @@ -65,8 +67,9 @@ def test_dataframe_info(capsys):
assert obj
verify_dataframe_info(vars, 'df', capsys, True)
verify_dataframe_info(vars, 'se', capsys, True)
verify_dataframe_info(vars, 'np', capsys, True)
verify_dataframe_info(vars, 'np1', capsys, True)
verify_dataframe_info(vars, 'ls', capsys, True)
verify_dataframe_info(vars, 'np2', capsys, True)
verify_dataframe_info(vars, 'obj', capsys, False)

def verify_dataframe_info(vars, name, capsys, hasInfo):
Expand Down Expand Up @@ -96,6 +99,27 @@ def test_dataframe_rows(capsys):
rows = get_data_frame_rows(info, 100, 200, capsys)
assert rows
assert rows['data'][0]['+h2'] == 'Fy3 W[pMT['
get_ipython().run_cell('''
import pandas as pd
import numpy as np
ls = list([10, 20, 30, 40])
df = pd.DataFrame(ls)
se = pd.Series(ls)
np1 = np.array(ls)
np2 = np.array([[1, 2, 3], [4, 5, 6]])
obj = {}
''')
vars = get_variables(capsys)
np2 = get_variable_value(vars, 'np2', capsys)
assert np2
info = get_data_frame_info(vars, 'np2', capsys)
assert 'rowCount' in info
assert info['rowCount'] == 2
rows = get_data_frame_rows(info, 0, 2, capsys)
assert rows
assert rows['data'][0]





3 changes: 2 additions & 1 deletion src/client/common/utils/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export namespace DataScience {
export const pythonInteractiveCreateFailed = localize('DataScience.pythonInteractiveCreateFailed', 'Failure to create a \'Python Interactive\' window. Try reinstalling the Python extension.');
export const jupyterGetVariablesExecutionError = localize('DataScience.jupyterGetVariablesExecutionError', 'Failure during variable extraction: \r\n{0}');
export const loadingMessage = localize('DataScience.loadingMessage', 'loading ...');
export const noRowsInDataViewer = localize('DataScience.noRowsInDataViewer', 'Fetching data ...');
export const fetchingDataViewer = localize('DataScience.fetchingDataViewer', 'Fetching data ...');
Copy link
Member

@IanMatthewHuff IanMatthewHuff Apr 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these are needed when consuming them in the tsx files. #Resolved

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you're right.


In reply to: 277431565 [](ancestors = 277431565)

export const noRowsInDataViewer = localize('DataScience.noRowsInDataViewer', 'No rows match current filter');
export const pandasTooOldForViewingFormat = localize('DataScience.pandasTooOldForViewingFormat', 'Python package \'pandas\' is version {0}. Version 0.20 or greater is required for viewing data.');
export const pandasRequiredForViewing = localize('DataScience.pandasRequiredForViewing', 'Python package \'pandas\' is required for viewing data.');
export const valuesColumn = localize('DataScience.valuesColumn', 'values');
Expand Down
9 changes: 0 additions & 9 deletions src/datascience-ui/data-explorer/emptyRowsView.css
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
.progress-bar {
margin:2px;
text-align: center;
}

.progress-container {
padding: 20px;
text-align:center;
}
14 changes: 3 additions & 11 deletions src/datascience-ui/data-explorer/emptyRowsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,14 @@ import * as React from 'react';
import { getLocString } from '../react-common/locReactSide';

export interface IEmptyRowsProps {
total: number;
current: number;
}

export const EmptyRowsView = (props: IEmptyRowsProps) => {
const percent = props.current / props.total * 100;
const percentText = `${Math.round(percent)}%`;
const style: React.CSSProperties = {
width: percentText
};
const message = getLocString('DataScience.noRowsInDataViewer', 'Fetching data ...');
export const EmptyRows = (_props: IEmptyRowsProps) => {
const message = getLocString('DataScience.noRowsInDataViewer', 'No rows match current filter');

return (
<div className='progress-container'>
<div className='container'>
{message}
<div className='progress-bar' style={style}>{percentText}</div>
</div>
);
};
8 changes: 6 additions & 2 deletions src/datascience-ui/data-explorer/mainPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { IJupyterVariable } from '../../client/datascience/types';
import { IMessageHandler, PostOffice } from '../react-common/postOffice';
import { StyleInjector } from '../react-common/styleInjector';
import { CellFormatter } from './cellFormatter';
import { EmptyRowsView } from './emptyRowsView';
import { EmptyRows } from './emptyRowsView';
import { ProgressBar } from './progressBar';
import { generateTestData } from './testData';

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

public componentDidUpdate() {
// Rebind our empty rows view to our new state.
this.emptyRows = EmptyRowsView.bind(this, {current: this.state.fetchedRowCount, total: this.state.actualRowCount});
this.emptyRows = this.state.fetchedRowCount === this.state.actualRowCount ?
EmptyRows.bind(this, {current: this.state.fetchedRowCount, total: this.state.actualRowCount}) :
ProgressBar.bind(this, {current: this.state.fetchedRowCount, total: this.state.actualRowCount});

this.getEmptyRows = (_props: any) => {
return this.emptyRows ? this.emptyRows() : <div/>;
};
Expand Down
9 changes: 9 additions & 0 deletions src/datascience-ui/data-explorer/progressBar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.progress-bar {
margin:2px;
text-align: center;
}

.progress-container {
padding: 20px;
text-align:center;
}
28 changes: 28 additions & 0 deletions src/datascience-ui/data-explorer/progressBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import './progressBar.css';

import * as React from 'react';
import { getLocString } from '../react-common/locReactSide';

export interface IEmptyRowsProps {
total: number;
current: number;
}

export const ProgressBar = (props: IEmptyRowsProps) => {
const percent = props.current / props.total * 100;
const percentText = `${Math.round(percent)}%`;
const style: React.CSSProperties = {
width: percentText
};
const message = getLocString('DataScience.fetchingDataViewer', 'Fetching data ...');

return (
<div className='progress-container'>
{message}
<div className='progress-bar' style={style}>{percentText}</div>
</div>
);
};