TS typing for Dataframe (#2382)

* initial TS typing

* first cut at Dataframe TS typing

* more Dataframe typing

* comments

* more Dataframe cleanup

* PR review fixes and improvements
This commit is contained in:
Bruce Martin
2021-08-17 10:43:40 -07:00
committed by GitHub
parent 3fdf5cac9d
commit 45cecad76a
39 changed files with 1298 additions and 1124 deletions
@@ -188,8 +188,10 @@ describe("AnnoMatrix", () => {
(fetch as any)
.once(serverMocks.annotationsObs(["n_genes"]))
.once(serverMocks.annotationsObs(["n_genes"]));
const ng1 = await am1.fetch("obs", "n_genes");
const ng2 = await am2.fetch("obs", "n_genes");
const ng1 = (await am1.fetch("obs", "n_genes")) as Dataframe;
const ng2 = (await am2.fetch("obs", "n_genes")) as Dataframe;
expect(ng1).toBeDefined();
expect(ng2).toBeDefined();
expect(ng1).toHaveLength(ng2.length);
expect(ng1.colIndex.labels()).toEqual(ng2.colIndex.labels());
expect(ng1.col("n_genes").asArray()).toEqual(
@@ -216,7 +218,7 @@ describe("AnnoMatrix", () => {
);
expect(base.getMatrixColumns("obs")).not.toContain("foo");
expect(am1.getMatrixColumns("obs")).toContain("foo");
const foo = await am1.fetch("obs", "foo");
const foo: Dataframe = await am1.fetch("obs", "foo");
expect(foo).toBeDefined();
expect(foo).toBeInstanceOf(Dataframe);
expect(foo).toHaveLength(am1.nObs);
@@ -12,6 +12,7 @@ import {
AnnoMatrixObsCrossfilter,
isubsetMask,
} from "../../../src/annoMatrix";
import { Dataframe } from "../../../src/util/dataframe";
import { rangeFill } from "../../../src/util/range";
enableFetchMocks();
@@ -132,7 +133,7 @@ describe("AnnoMatrixCrossfilter", () => {
)
);
const df = await annoMatrix.fetch("obs", "louvain");
const df: Dataframe = await annoMatrix.fetch("obs", "louvain");
const values = df.col("louvain").asArray();
const selected = xfltr.allSelectedMask();
values.every(
@@ -265,7 +266,11 @@ describe("AnnoMatrixCrossfilter", () => {
expect(xfltr).toBeDefined();
expect(xfltr.countSelected()).toEqual(240);
const df = await annoMatrixSubset.fetch("obs", "louvain");
const df: Dataframe = (await annoMatrixSubset.fetch(
"obs",
"louvain"
)) as Dataframe;
expect(df).toBeDefined();
const values = df.col("louvain").asArray();
const selected = xfltr.allSelectedMask();
values.every(
@@ -354,7 +359,7 @@ describe("AnnoMatrixCrossfilter", () => {
).toHaveLength(1);
// check data update.
const df = await xfltr.annoMatrix.fetch("obs", "foo");
const df: Dataframe = await xfltr.annoMatrix.fetch("obs", "foo");
expect(
df
.col("foo")
@@ -649,7 +654,7 @@ describe("AnnoMatrixCrossfilter", () => {
values: ["purple"],
});
expect(xfltr2.countSelected()).toEqual(2);
expect(xfltr2.allSelectedLabels()).toEqual(Int32Array.from([0, 10]));
expect(xfltr2.allSelectedLabels()).toEqual(Array.from([0, 10]));
});
test("resetObsColumnValues", async () => {
@@ -43,7 +43,6 @@ function getEncodedDataframe(colNames: any, length: any, colSchemas: any) {
const colIndex = new KeyIndex(colNames);
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
const columns = colSchemas.map((s: any) => makeMockColumn(s, length));
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'KeyIndex' is not assignable to p... Remove this comment to see the full error message
const df = new Dataframe([length, colNames.length], columns, null, colIndex);
const body = encodeMatrixFBS(df);
return body;
@@ -56,7 +55,6 @@ export function dataframeResponse(colNames: any, columns: any) {
[columns[0].length, colNames.length],
columns,
null,
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'KeyIndex' is not assignable to p... Remove this comment to see the full error message
colIndex
);
const body = encodeMatrixFBS(df);