Open
Description
When data contains a BigInt
variable, trying to apply normalize
on this variable throws an error: TypeError: Cannot convert a BigInt value to a number
.
I've created a small notebook to reproduce the issue:
https://observablehq.com/@juba/plot-normalize-bigint-error
It seems that the error may come from this line, but I'm far from an expert on this domain so I may be mistaken:
Activity
BigInt
error in stateage example juba/pyobsplot#40Fil commentedon Aug 28, 2024
Yes you can fix this example by doing
to try, just run
yarn prepublishOnly
in your repo, then upload the file to your notebook and add a cell that says:However I don't think this is enough, because we need to fix all the different bases.
In that case the patch is simpler:
function normalizeBasis(basis) { return { mapIndex(I, S, T) { + S = S.map(Number); const b = +basis(I, S); for (const i of I) { T[i] = S[i] === null ? NaN : S[i] / b;
but we should avoid doing this if the values are already numbers (not big).
So maybe instead we do:
Fil commentedon Aug 28, 2024
Also let's create a more meaningful example / test plot. We often get BigInt as the result of a sql count, so maybe simulate this like so:
add BigInt support to the normalize transform
juba commentedon Aug 28, 2024
I can confirm that the issue seems fixed with your PR at #2155.
Just as a side note, I get these
BigInt
values because I'm passing arrow data coming from pandas and polars, which themselves seem to now import CSV files with 64 bits integers by default...Thanks!
Fil commentedon Aug 28, 2024