Skip to content

Commit

Permalink
TS typing for Dataframe (#2382)
Browse files Browse the repository at this point in the history
* initial TS typing

* first cut at Dataframe TS typing

* more Dataframe typing

* comments

* more Dataframe cleanup

* PR review fixes and improvements
  • Loading branch information
Bruce Martin authored Aug 17, 2021
1 parent 3fdf5ca commit 45cecad
Show file tree
Hide file tree
Showing 39 changed files with 1,302 additions and 1,128 deletions.
8 changes: 5 additions & 3 deletions client/__tests__/util/annoMatrix/annoMatrix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
13 changes: 9 additions & 4 deletions client/__tests__/util/annoMatrix/crossfilter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
AnnoMatrixObsCrossfilter,
isubsetMask,
} from "../../../src/annoMatrix";
import { Dataframe } from "../../../src/util/dataframe";
import { rangeFill } from "../../../src/util/range";

enableFetchMocks();
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 () => {
Expand Down
2 changes: 0 additions & 2 deletions client/__tests__/util/annoMatrix/serverMocks/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions client/__tests__/util/centroid.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import cloneDeep from "lodash.clonedeep";

import { NumberArray } from "../../src/common/types/arraytypes";
import calcCentroid from "../../src/util/centroid";
import quantile from "../../src/util/quantile";
import { matrixFBSToDataframe } from "../../src/util/stateManager/matrix";
import * as REST from "./stateManager/sampleResponses";
import { indexEntireSchema } from "../../src/util/stateManager/schemaHelpers";
import { normalizeWritableCategoricalSchema } from "../../src/annoMatrix/normalize";
import { Dataframe } from "../../src/util/dataframe";

describe("centroid", () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
let schema: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
let obsAnnotations: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
let obsLayout: any;
let obsAnnotations: Dataframe;
let obsLayout: Dataframe;

beforeAll(() => {
schema = indexEntireSchema(cloneDeep(REST.schema.schema));
Expand Down Expand Up @@ -43,8 +43,8 @@ describe("centroid", () => {

// This expected result assumes that all cells belong in all categorical values inside of sample response
const expectedResult = [
quantile([0.5], obsLayout.col("umap_0").asArray())[0],
quantile([0.5], obsLayout.col("umap_1").asArray())[0],
quantile([0.5], obsLayout.col("umap_0").asArray() as NumberArray)[0],
quantile([0.5], obsLayout.col("umap_1").asArray() as NumberArray)[0],
];

// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
Expand All @@ -68,8 +68,8 @@ describe("centroid", () => {

// This expected result assumes that all cells belong in all categorical values inside of sample response
const expectedResult = [
quantile([0.5], obsLayout.col("umap_0").asArray())[0],
quantile([0.5], obsLayout.col("umap_1").asArray())[0],
quantile([0.5], obsLayout.col("umap_0").asArray() as NumberArray)[0],
quantile([0.5], obsLayout.col("umap_1").asArray() as NumberArray)[0],
];

// eslint-disable-next-line @typescript-eslint/no-explicit-any --- FIXME: disabled temporarily on migrate to TS.
Expand Down
Loading

0 comments on commit 45cecad

Please sign in to comment.