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

Check nullCount in Series.toTypedArray #207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions __tests__/series.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,14 @@ describe("series", () => {
const actual = s.round({ decimals: 2 });
expect(actual).toSeriesEqual(expected);
});
test("toTypedArray handles nulls", () => {
const s = pl.Series("ints and nulls", [1, 2, 3, null, 5], pl.UInt8);
expect(() => s.toTypedArray()).toThrow();
expect(() => s.dropNulls().toTypedArray()).not.toThrow();
expect(s.dropNulls().toTypedArray()).toStrictEqual(
new Uint8Array([1, 2, 3, 5]),
);
});
});
describe("comparators & math", () => {
test("add/plus", () => {
Expand Down
2 changes: 1 addition & 1 deletion polars/series/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ export function _Series(_s: any): Series {
return _s.toArray();
},
toTypedArray() {
if (!this.hasValidity()) {
if (!this.hasValidity() || this.nullCount() === 0) {
return _s.toTypedArray();
}
throw new Error("data contains nulls, unable to convert to TypedArray");
Expand Down