forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expose API to show DS Data Viewer component from external extension #12045
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
388f87d
Issue#12033 Expose API to show Data Viewer component from an external…
sevillal 85783ff
Issue#12033 Add headers and comments to important updated/new code
sevillal 3a6ad6c
Issue12033 Fix review comments:
sevillal fc0dcef
Issue#12033 Fix hygiene
sevillal d161502
Issue#12033 Change IRowsResponse to be of type any[]
sevillal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/client/datascience/data-viewing/jupyterVariableDataProvider.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| 'use strict'; | ||
| import '../../common/extensions'; | ||
|
|
||
| import { inject, injectable, named } from 'inversify'; | ||
|
|
||
| import { Identifiers } from '../constants'; | ||
| import { IJupyterVariable, IJupyterVariableDataProvider, IJupyterVariables, INotebook } from '../types'; | ||
| import { DataViewerDependencyService } from './dataViewerDependencyService'; | ||
| import { ColumnType, IDataFrameInfo, IRowsResponse } from './types'; | ||
|
|
||
| @injectable() | ||
| export class JupyterVariableDataProvider implements IJupyterVariableDataProvider { | ||
| private initialized: boolean = false; | ||
| private notebook: INotebook | undefined; | ||
| private variable: IJupyterVariable | undefined; | ||
|
|
||
| constructor( | ||
| @inject(IJupyterVariables) @named(Identifiers.ALL_VARIABLES) private variableManager: IJupyterVariables, | ||
| @inject(DataViewerDependencyService) private dependencyService: DataViewerDependencyService | ||
| ) {} | ||
|
|
||
| /** | ||
| * Normalizes column types to the types the UI component understands. | ||
| * Defaults to 'string'. | ||
| * @param columns | ||
| * @returns Array of columns with normalized type | ||
| */ | ||
| private static getNormalizedColumns(columns: { key: string; type: string }[]): { key: string; type: ColumnType }[] { | ||
| return columns.map((column: { key: string; type: string }) => { | ||
| let normalizedType: ColumnType; | ||
| switch (column.type) { | ||
| case 'bool': | ||
| normalizedType = ColumnType.Bool; | ||
| break; | ||
| case 'integer': | ||
| case 'int32': | ||
| case 'int64': | ||
| case 'float': | ||
| case 'float32': | ||
| case 'float64': | ||
| case 'number': | ||
| normalizedType = ColumnType.Number; | ||
| break; | ||
| default: | ||
| normalizedType = ColumnType.String; | ||
| } | ||
| return { | ||
| key: column.key, | ||
| type: normalizedType | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| public dispose(): void { | ||
| return; | ||
| } | ||
|
|
||
| public setDependencies(variable: IJupyterVariable, notebook: INotebook): void { | ||
| this.notebook = notebook; | ||
| this.variable = variable; | ||
| } | ||
|
|
||
| public async getDataFrameInfo(): Promise<IDataFrameInfo> { | ||
| let dataFrameInfo: IDataFrameInfo = {}; | ||
| await this.ensureInitialized(); | ||
| if (this.variable && this.notebook) { | ||
| dataFrameInfo = { | ||
| columns: this.variable.columns | ||
| ? JupyterVariableDataProvider.getNormalizedColumns(this.variable.columns) | ||
| : this.variable.columns, | ||
| indexColumn: this.variable.indexColumn, | ||
| rowCount: this.variable.rowCount | ||
| }; | ||
| } | ||
| return dataFrameInfo; | ||
| } | ||
|
|
||
| public async getAllRows() { | ||
| let allRows: IRowsResponse = []; | ||
| await this.ensureInitialized(); | ||
| if (this.variable && this.variable.rowCount && this.notebook) { | ||
| const dataFrameRows = await this.variableManager.getDataFrameRows( | ||
| this.variable, | ||
| this.notebook, | ||
| 0, | ||
| this.variable.rowCount | ||
| ); | ||
| allRows = dataFrameRows && dataFrameRows.data ? (dataFrameRows.data as IRowsResponse) : []; | ||
| } | ||
| return allRows; | ||
| } | ||
|
|
||
| public async getRows(start: number, end: number) { | ||
| let rows: IRowsResponse = []; | ||
| await this.ensureInitialized(); | ||
| if (this.variable && this.variable.rowCount && this.notebook) { | ||
| const dataFrameRows = await this.variableManager.getDataFrameRows(this.variable, this.notebook, start, end); | ||
| rows = dataFrameRows && dataFrameRows.data ? (dataFrameRows.data as IRowsResponse) : []; | ||
| } | ||
| return rows; | ||
| } | ||
|
|
||
| private async ensureInitialized(): Promise<void> { | ||
| // Postpone pre-req and variable initialization until data is requested. | ||
| if (!this.initialized && this.variable && this.notebook) { | ||
| this.initialized = true; | ||
| await this.dependencyService.checkAndInstallMissingDependencies(this.notebook.getMatchingInterpreter()); | ||
| this.variable = await this.variableManager.getDataFrameInfo(this.variable, this.notebook); | ||
| } | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
src/client/datascience/data-viewing/jupyterVariableDataProviderFactory.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| 'use strict'; | ||
| import '../../common/extensions'; | ||
|
|
||
| import { inject, injectable } from 'inversify'; | ||
|
|
||
| import { IServiceContainer } from '../../ioc/types'; | ||
| import { | ||
| IJupyterVariable, | ||
| IJupyterVariableDataProvider, | ||
| IJupyterVariableDataProviderFactory, | ||
| INotebook | ||
| } from '../types'; | ||
|
|
||
| @injectable() | ||
| export class JupyterVariableDataProviderFactory implements IJupyterVariableDataProviderFactory { | ||
| constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) {} | ||
|
|
||
| public async create(variable: IJupyterVariable, notebook: INotebook): Promise<IJupyterVariableDataProvider> { | ||
| const jupyterVariableDataProvider = this.serviceContainer.get<IJupyterVariableDataProvider>( | ||
| IJupyterVariableDataProvider | ||
| ); | ||
| jupyterVariableDataProvider.setDependencies(variable, notebook); | ||
| return jupyterVariableDataProvider; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we swallowing errors here. Not sure this is the right thing to do.
How about changing from
process.cwdtodataExplorereDir, makes it future proof as well, if we wanted to load soemthing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DonJayamanne great comments :) thanks
Error swallowing: hmm I think it is because this call was done from the constructor, I moved here to make sure the webpanel is loaded before calling setTitle and show. I never realized the error swallowing though, will remove it.
Directory: Good point, just wondering if there is another reason why it was done like that. @rchiodo @IanMatthewHuff any thoughts?