Skip to content

Commit

Permalink
Show index column only for DataFrame and Series
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl committed Mar 24, 2021
1 parent df50956 commit 2bf99e3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
24 changes: 14 additions & 10 deletions src/datascience-ui/data-explorer/mainPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,20 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
type: ColumnType.Number
};
const columns = [rowNumberColumn].concat(variable.columns);
return columns.map((c: { key: string; type: ColumnType }, i: number) => {
return {
type: c.type,
field: c.key.toString(),
id: `${i}`,
name: c.key.toString(),
sortable: true,
formatter: cellFormatterFunc
};
});
return columns.reduce((accum: Slick.Column<Slick.SlickData>[], c: { key: string; type: ColumnType }, i: number) => {
// Only show index column for pandas DataFrame and Series
if ((variable?.type === 'DataFrame' || variable?.type === 'Series' || c.key !== this.state.indexColumn)) {
accum.push({
type: c.type,
field: c.key.toString(),
id: `${i}`,
name: c.key.toString(),
sortable: true,
formatter: cellFormatterFunc
} as Slick.Column<Slick.SlickData>);
}
return accum;
}, []);
}
return [];
}
Expand Down
14 changes: 12 additions & 2 deletions src/test/datascience/dataviewer.functional.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,17 @@ suite('DataScience DataViewer tests', () => {
assert.ok(dv, 'DataViewer not created');
await gotAllRows;

verifyRows(wrapper.wrapper, [0, 0, 1, 1, 2, 2, 3, 3]);
verifyRows(wrapper.wrapper, [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]);
});

runMountedTest('Transposed Data Frame', async (wrapper) => {
await injectCode('import pandas as pd\r\ndata = [["tom", 10], ["nick", 15], ["juli", 14]]\r\ndf = pd.DataFrame(data, columns=["Name", "Age"])\r\ndf = df.transpose()');
const gotAllRows = getCompletedPromise(wrapper);
const dv = await createJupyterVariableDataViewer('df', 'DataFrame');
assert.ok(dv, 'DataViewer not created');
await gotAllRows;

verifyRows(wrapper.wrapper, [0, "Name", "tom", "nick", "juli", 1, "Age", "10", "15", "14"]);
});

runMountedTest('List', async (wrapper) => {
Expand All @@ -304,7 +314,7 @@ suite('DataScience DataViewer tests', () => {
assert.ok(dv, 'DataViewer not created');
await gotAllRows;

verifyRows(wrapper.wrapper, [0, 0, 1, 1, 2, 2, 3, 3]);
verifyRows(wrapper.wrapper, [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]);
});

runMountedTest('np.array', async (wrapper) => {
Expand Down

0 comments on commit 2bf99e3

Please sign in to comment.