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

Add slice data functional tests #5057

Merged
merged 13 commits into from
Mar 9, 2021
1 change: 1 addition & 0 deletions news/3 Code Health/5066.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add tests for data viewer slice data functionality.
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ def _VSCODE_convertTensorToDataFrame(tensor, start=None, end=None):
def _VSCODE_convertToDataFrame(df, start=None, end=None):
vartype = type(df)
if isinstance(df, list):
df = _VSCODE_pd.DataFrame(df)
df = _VSCODE_pd.DataFrame(df).iloc[start:end]
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these work if start and end are none?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, that corresponds to no slice i.e. it returns the full variable

elif isinstance(df, _VSCODE_pd.Series):
df = _VSCODE_pd.Series.to_frame(df)
df = _VSCODE_pd.Series.to_frame(df).iloc[start:end]
elif isinstance(df, dict):
df = _VSCODE_pd.Series(df)
df = _VSCODE_pd.Series.to_frame(df)
df = _VSCODE_pd.Series.to_frame(df).iloc[start:end]
elif hasattr(df, "toPandas"):
df = df.toPandas()
df = df.toPandas().iloc[start:end]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Broke chunking in #4951

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, but the comment doesn't make sense.
It looks like this is a bug fix.

Copy link
Member

Choose a reason for hiding this comment

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

I'm a tiny bit confused as well. This is merging into more-styles and currently there is also a PR open for more-styles into main?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this PR depends on the Checkbox change in more-styles. But I'm merging the style changes into main, then this into main. And yes this is a bug fix.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, that works for me. I think that personally I would just park it until style was into main and then PR against main so I could see test runs and what not. But small enough change that I'm down with approving now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Somehow I thought we used to get test runs even on PRs not going into main... That's totally fair, my bad. Can't wait for GitHub to add stacked diffs 😭

elif (
hasattr(vartype, "__name__") and vartype.__name__ in _VSCODE_allowedTensorTypes
):
Expand All @@ -109,7 +109,7 @@ def _VSCODE_convertToDataFrame(df, start=None, end=None):
"""Disabling bandit warning for try, except, pass. We want to swallow all exceptions here to not crash on
variable fetching"""
try:
temp = _VSCODE_pd.DataFrame(df)
temp = _VSCODE_pd.DataFrame(df).iloc[start:end]
df = temp
except: # nosec
pass
Expand Down
4 changes: 0 additions & 4 deletions src/client/datascience/jupyter/kernelVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ export class KernelVariables implements IJupyterVariables {
// Import the data frame script directory if we haven't already
await this.importDataFrameScripts(notebook);

if (targetVariable.rowCount) {
end = Math.min(end, targetVariable.rowCount);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The row start and end however are already evaluated relative to the slice variable info, so this check is unnecessary.


let expression = targetVariable.name;
if (sliceExpression) {
expression = `${targetVariable.name}${sliceExpression}`;
Expand Down
2 changes: 0 additions & 2 deletions src/datascience-ui/data-explorer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import '../common/index.css';

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { initializeIcons } from '@fluentui/react';

import { IVsCodeApi } from '../react-common/postOffice';
import { detectBaseTheme } from '../react-common/themeDetector';
Expand All @@ -21,7 +20,6 @@ import { MainPanel } from './mainPanel';
export declare function acquireVsCodeApi(): IVsCodeApi;

const baseTheme = detectBaseTheme();
initializeIcons();

/* eslint-disable */
ReactDOM.render(
Expand Down
3 changes: 3 additions & 0 deletions src/datascience-ui/data-explorer/mainPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import '../react-common/seti/seti.less';
import { SliceControl } from './sliceControl';
import { debounce } from 'lodash';

import { initializeIcons } from '@fluentui/react';
initializeIcons(); // Register all FluentUI icons being used to prevent developer console errors

const SliceableTypes: Set<string> = new Set<string>(['ndarray', 'Tensor', 'EagerTensor']);

// Our css has to come after in order to override body styles
Expand Down
1 change: 1 addition & 0 deletions src/datascience-ui/data-explorer/sliceControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const styleOverrides = {
fontFamily: 'var(--vscode-font-family)',
fontWeight: 'var(--vscode-font-weight)',
fontSize: 'var(--vscode-font-size)',
border: 'var(--vscode-dropdown-border)',
':focus': {
color: 'var(--vscode-dropdown-foreground)'
},
Expand Down
Loading