-
Notifications
You must be signed in to change notification settings - Fork 128
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2371 +/- ##
=======================================
Coverage 68.23% 68.23%
=======================================
Files 127 127
Lines 12259 12259
=======================================
Hits 8365 8365
Misses 3894 3894
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
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.
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 🔥 🙏 !
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 |
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 👏 🎉 |
@bkmartinjr Hi Bruce!! Can you help review this PR to see what types we need to adjust? Thanks so much!! |
client/src/annoMatrix/annoMatrix.ts
Outdated
// @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> { |
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.
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.
6b90c94
to
3beb8d7
Compare
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.
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(); |
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.
@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!
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.
@tihuan - please review Mim's comments and discussion for an explanation. The runtime changed.
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.
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.
Oh perfect! Thanks so much, both 🙏
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.
LGTM
@@ -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( |
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.
Hmm yeah interesting that TS is saying toDrop Int32Array | (string | number)[]
is not callable 🤔 Feels like a TS bug 😂
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.
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.
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;
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.
ALL DONE!! Thanks so much for all the amazing typings, @MillenniumFalconMechanic 🔥 You are the coolest!!
Co-authored-by: Timmy Huang <[email protected]>
Co-authored-by: Timmy Huang <[email protected]>
Co-authored-by: Timmy Huang <[email protected]>
Co-authored-by: Timmy Huang <[email protected]>
Co-authored-by: Timmy Huang <[email protected]>
Co-authored-by: Timmy Huang <[email protected]>
55ac88f
to
9103cad
Compare
Reviewers
Functional:
@colinmegill, @seve, @tihuan
Changes
src/annoMatrix
directory.src/annoMatrix
directory (typings in tests are still to do).actions/embedding.ts
to fix compile error introduced by usingField.emb
rather than"emb"
.annomatrix.ts L225 & L227 - 229crossfilter.ts L207loader.ts L211loader.ts L234loader.ts L242loader.ts L378schema.ts L38views.ts L46views.ts L159wherecache.ts L172