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

Added typings to annoMatrix dir. (#2365) #2371

Merged
merged 10 commits into from
Aug 18, 2021
Merged

Conversation

MillenniumFalconMechanic
Copy link
Collaborator

@MillenniumFalconMechanic MillenniumFalconMechanic commented Aug 8, 2021

Reviewers

Functional:
@colinmegill, @seve, @tihuan


Changes

@codecov
Copy link

codecov bot commented Aug 8, 2021

Codecov Report

Merging #2371 (ebf1215) into main (08b03ac) will not change coverage.
The diff coverage is n/a.

❗ Current head ebf1215 differs from pull request most recent head 9103cad. Consider uploading reports for the commit 9103cad to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2371   +/-   ##
=======================================
  Coverage   68.23%   68.23%           
=======================================
  Files         127      127           
  Lines       12259    12259           
=======================================
  Hits         8365     8365           
  Misses       3894     3894           
Flag Coverage Δ
frontend 66.99% <ø> (ø)
javascript 66.99% <ø> (ø)
smokeTest ∅ <ø> (∅)
smokeTestAnnotations ∅ <ø> (∅)
unitTest 66.99% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 08b03ac...9103cad. Read the comment docs.

@MillenniumFalconMechanic MillenniumFalconMechanic changed the title WIP - Added typings to annoMatrix dir. (#1322) Added typings to annoMatrix dir. (#1322) Aug 9, 2021
@MillenniumFalconMechanic MillenniumFalconMechanic changed the title Added typings to annoMatrix dir. (#1322) Added typings to annoMatrix dir. (#2365) Aug 9, 2021
Copy link
Contributor

@tihuan tihuan left a comment

Choose a reason for hiding this comment

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

Just went through all the files! Thanks so much for adding all the types 🙏 It's incredibly helpful for understanding what's going on now 🤩

For my own education, how did you figure out when a function accepts/returns different typed arrays?

For example, client/src/annoMatrix/annoMatrix.ts:428:

abstract setObsColumnValues(
    col: string,
    obsLabels: Int32Array, // <-- how did you figure out this is Int32Array? 
    value: ObsColumnValue
  ): Promise<AnnoMatrix>;

or:

client/src/annoMatrix/viewCreators.ts:16:

export function isubsetMask(
  annoMatrix: AnnoMatrix,
  obsMask: Uint8Array // <---- how did you figure this out?
): AnnoMatrixRowSubsetView {
  /*
		Subset annomatrix to contain the rows which have truish value in the mask.
    Maks length must equal annoMatrix.nObs (row count).
	*/
  return isubset(annoMatrix, _maskToList(obsMask));
}

Thanks again!

It definitely feels like a puzzle and you nailed it 🔥 🙏 !

client/src/annoMatrix/annoMatrix.ts Show resolved Hide resolved
client/src/annoMatrix/annoMatrix.ts Outdated Show resolved Hide resolved
client/src/annoMatrix/whereCache.ts Outdated Show resolved Hide resolved
client/x-gene-sets-LWXPSCFP.csv Outdated Show resolved Hide resolved
client/src/annoMatrix/annoMatrix.ts Show resolved Hide resolved
client/src/annoMatrix/crossfilter.ts Outdated Show resolved Hide resolved
client/src/annoMatrix/crossfilter.ts Outdated Show resolved Hide resolved
client/src/annoMatrix/fetchHelpers.ts Show resolved Hide resolved
client/src/annoMatrix/query.ts Outdated Show resolved Hide resolved
client/src/annoMatrix/whereCache.ts Outdated Show resolved Hide resolved
@MillenniumFalconMechanic
Copy link
Collaborator Author

For my own education, how did you figure out when a function accepts/returns different typed arrays?

For example, client/src/annoMatrix/annoMatrix.ts:428:

abstract setObsColumnValues(
    col: string,
    obsLabels: Int32Array, // <-- how did you figure out this is Int32Array? 
    value: ObsColumnValue
  ): Promise<AnnoMatrix>;

or:

client/src/annoMatrix/viewCreators.ts:16:

export function isubsetMask(
  annoMatrix: AnnoMatrix,
  obsMask: Uint8Array // <---- how did you figure this out?
): AnnoMatrixRowSubsetView {
  /*
		Subset annomatrix to contain the rows which have truish value in the mask.
    Maks length must equal annoMatrix.nObs (row count).
	*/
  return isubset(annoMatrix, _maskToList(obsMask));
}

Hi Timmy, when working through the typings, I did a combination of looking at the code itself, looking at the comments in the code, looking at possible values in the tests and also inspecting values at runtime. I suspect obsLabels: Int32Array and obsMask: Uint8Array came from inspecting the code at runtime. I may not have exercised all of the possible paths or values but this is my current best estimate at the types!

@tihuan
Copy link
Contributor

tihuan commented Aug 11, 2021

For my own education, how did you figure out when a function accepts/returns different typed arrays?
For example, client/src/annoMatrix/annoMatrix.ts:428:

abstract setObsColumnValues(
    col: string,
    obsLabels: Int32Array, // <-- how did you figure out this is Int32Array? 
    value: ObsColumnValue
  ): Promise<AnnoMatrix>;

or:
client/src/annoMatrix/viewCreators.ts:16:

export function isubsetMask(
  annoMatrix: AnnoMatrix,
  obsMask: Uint8Array // <---- how did you figure this out?
): AnnoMatrixRowSubsetView {
  /*
		Subset annomatrix to contain the rows which have truish value in the mask.
    Maks length must equal annoMatrix.nObs (row count).
	*/
  return isubset(annoMatrix, _maskToList(obsMask));
}

Hi Timmy, when working through the typings, I did a combination of looking at the code itself, looking at the comments in the code, looking at possible values in the tests and also inspecting values at runtime. I suspect obsLabels: Int32Array and obsMask: Uint8Array came from inspecting the code at runtime. I may not have exercised all of the possible paths or values but this is my current best estimate at the types!

Wow that's so thorough and totally makes sense 🤩 Thanks for sharing your strategy!

Yeah @bkmartinjr is back now, so let's get his eyes on this too 👏 🎉

@tihuan
Copy link
Contributor

tihuan commented Aug 11, 2021

@bkmartinjr Hi Bruce!! Can you help review this PR to see what types we need to adjust? Thanks so much!!

@tihuan tihuan requested a review from bkmartinjr August 11, 2021 18:13
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'field' implicitly has an 'any' type.
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types --- FIXME: disabled temporarily on migrate to TS.
fetch(field, q) {
fetch(field: Field, q: Query): Promise<Dataframe | undefined> {
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment in query.ts about fixing the definition of Query.

I recommend Query be a singleton query, and this function be redefined as:

fetch(field: Field, q: Query | Query[])

prefetch() and _fetch() need the same edit.

Copy link
Contributor

@bkmartinjr bkmartinjr left a comment

Choose a reason for hiding this comment

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

Looking great - only one issue remaining, plus two nits:

  • Issue: the viewOf change introduced a bug into middleware.ts (gc). Left a coment.
  • Nit: suggestion on how to remove an error suppression in viewCreators.ts::_maskToList()
  • Nit: suggestion of how to resolve the error in the type signature for crossfilter::fillByIsSelected()

Other than those (especially the first), LGTM!

@@ -34,15 +35,15 @@ describe("AnnoMatrix", () => {
expect(annoMatrix.nObs).toEqual(serverMocks.schema.schema.dataframe.nObs);
expect(annoMatrix.nVar).toEqual(serverMocks.schema.schema.dataframe.nVar);
expect(annoMatrix.isView).toBeFalsy();
expect(annoMatrix.viewOf).toBeUndefined();
Copy link
Contributor

Choose a reason for hiding this comment

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

@bkmartinjr this looks like the opposite of the original assertion (from undefined to now annomatrix), does this indicate runtime code change or something else? Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

@tihuan - please review Mim's comments and discussion for an explanation. The runtime changed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tihuan, discussion is here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh perfect! Thanks so much, both 🙏

Copy link
Contributor

@bkmartinjr bkmartinjr left a comment

Choose a reason for hiding this comment

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

LGTM

client/__tests__/util/annoMatrix/whereCache.test.ts Outdated Show resolved Hide resolved
client/__tests__/util/annoMatrix/whereCache.test.ts Outdated Show resolved Hide resolved
client/__tests__/util/annoMatrix/whereCache.test.ts Outdated Show resolved Hide resolved
client/src/annoMatrix/annoMatrix.ts Outdated Show resolved Hide resolved
@@ -629,49 +641,49 @@ Return cache keys for columns associated with this query. May return
// ", "
// )}]`
// );
// @ts-expect-error --- TODO revisit:
// `reduce`: This expression is not callable.
this._cache[field] = toDrop.reduce(
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm yeah interesting that TS is saying toDrop Int32Array | (string | number)[] is not callable 🤔 Feels like a TS bug 😂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tihuan, I need to spend some time looking through this and this but was thinking they might be applicable to a couple of suppressions I have added.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ooh thanks so much for research, Mim! Ahh I see, so it sounds like Int32Array and a regular array have difference reduce signatures, because Int32Array can guarantee T to be number, but regular array's T can be number | string, and the array arg type is different too array: Int32Array vs. array: T[]. So TS can't type anything for us in this case. But the error message not callable definitely seems misleading 😆

// Int32Array
reduce(callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: Int32Array) => number, initialValue: number): number;

// Array
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T): T;

client/src/annoMatrix/crossfilter.ts Show resolved Hide resolved
client/src/annoMatrix/crossfilter.ts Show resolved Hide resolved
client/src/annoMatrix/loader.ts Show resolved Hide resolved
Copy link
Contributor

@tihuan tihuan left a comment

Choose a reason for hiding this comment

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

ALL DONE!! Thanks so much for all the amazing typings, @MillenniumFalconMechanic 🔥 You are the coolest!!

http://gph.is/1xZTNWq

client/src/annoMatrix/middleware.ts Outdated Show resolved Hide resolved
client/src/annoMatrix/views.ts Show resolved Hide resolved
Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
Co-authored-by: Timmy Huang <tihuan@users.noreply.github.com>
@MillenniumFalconMechanic MillenniumFalconMechanic deleted the mim/annoMatrix branch August 18, 2021 20:18
bkmartinjr pushed a commit that referenced this pull request Aug 19, 2021
This was referenced Aug 19, 2021
blrnw3 added a commit that referenced this pull request Oct 4, 2021
Categoricals can have nulls
blrnw3 added a commit that referenced this pull request Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants