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

Mishandling of Arrow's null values #2194

Closed
Fil opened this issue Oct 10, 2024 · 4 comments · Fixed by #2195
Closed

Mishandling of Arrow's null values #2194

Fil opened this issue Oct 10, 2024 · 4 comments · Fixed by #2195
Assignees
Labels
bug Something isn’t working

Comments

@Fil
Copy link
Contributor

Fil commented Oct 10, 2024

In #2115 we did not consider that the arrow vector.toArray() can return anything when a value is null. (See observablehq/framework#1738 for a concrete consequence).

After calling vector.toArray we have to clear out the null values (that can be skipped if there are no nulls).

@Fil Fil added the bug Something isn’t working label Oct 10, 2024
@Fil Fil self-assigned this Oct 10, 2024
Fil added a commit that referenced this issue Oct 10, 2024
@mbostock
Copy link
Member

Can you find documentation for this? How are you supposed to get the value out of a vector??

@Fil
Copy link
Contributor Author

Fil commented Oct 10, 2024

The closest I've found is @domoritz saying that toArray() is “often not generating what people want” (ref).

I've found the code around here but I'm not fully grokking it.
https://github.com/apache/arrow/blob/8be5f9c6b41ddd840939602016811aa9c739f0a3/js/src/visitor/iterator.ts#L118

@domoritz
Copy link
Contributor

Can you give me a minimal example with arrow? I suspect we can improve toArray() but what I meany by the comment is that you often simply iterate over the arrow vector or table and treat it like an array.

for (const el of vector) {
     console.log(el);
}

@Fil
Copy link
Contributor Author

Fil commented Oct 10, 2024

❯ cat v.js
import {arrow}  from "https://deno.land/x/[email protected]/mod.ts";
const vector = arrow.tableFromArrays({v: [1, null, 2]}).getChild("v");

console.log(vector.toArray());
console.log([...vector]);
console.log(vector.toArray().map((d, i) => vector.isValid(i) ? d : NaN));
❯ deno v.js
Float64Array(3) [ 1, 0, 2 ]
[ 1, null, 2 ]
Float64Array(3) [ 1, NaN, 2 ]

In my real use case, the 0 in the middle was a "random" float32 derived from dirty memory, which made a different chart on each invocation — but the crucial point is that toArray() does not restitute nulls (and so we have a bug in Plot, because we didn't consider this behavior).

@Fil Fil closed this as completed in #2195 Oct 11, 2024
@Fil Fil closed this as completed in d707835 Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants