Skip to content

Commit d9de2e9

Browse files
authored
Fixing documentation, adding a test (pola-rs#103)
1 parent 8563d24 commit d9de2e9

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

__tests__/io.test.ts

+20-4
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,23 @@ describe("stream", () => {
346346
a: pl.Series("a", [1, 2, 3, 4], pl.Int64),
347347
b: pl.Series("b", [2, 2, 2, 2], pl.Int64),
348348
});
349-
const df = await pl.readJSONStream(readStream);
350-
expect(df).toFrameEqual(expected);
349+
const actual = await pl.readJSONStream(readStream);
350+
expect(actual).toFrameEqual(expected);
351+
});
352+
353+
test("readJSON:lines", async () => {
354+
const readStream = new Stream.Readable({ read() {} });
355+
readStream.push(`${JSON.stringify({ a: 1, b: 2 })} \n`);
356+
readStream.push(`${JSON.stringify({ a: 2, b: 2 })} \n`);
357+
readStream.push(`${JSON.stringify({ a: 3, b: 2 })} \n`);
358+
readStream.push(`${JSON.stringify({ a: 4, b: 2 })} \n`);
359+
readStream.push(null);
360+
const actual = await pl.readJSONStream(readStream, { format: "lines" });
361+
const expected = pl.DataFrame({
362+
a: pl.Series("a", [1, 2, 3, 4], pl.Int64),
363+
b: pl.Series("b", [2, 2, 2, 2], pl.Int64),
364+
});
365+
expect(actual).toFrameEqual(expected);
351366
});
352367

353368
test("readJSON:error", async () => {
@@ -357,7 +372,8 @@ describe("stream", () => {
357372
readStream.push(`${JSON.stringify({ a: 3, b: 2 })} \n`);
358373
readStream.push("not parseable json ");
359374
readStream.push(null);
360-
361-
await expect(pl.readJSONStream(readStream)).rejects.toBeDefined();
375+
await expect(
376+
pl.readJSONStream(readStream, { format: "lines" }),
377+
).rejects.toBeDefined();
362378
});
363379
});

polars/io.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ export function readCSVStream(stream, options?) {
669669
* >>> readStream.push(`${JSON.stringify({a: 4, b: 2})} \n`);
670670
* >>> readStream.push(null);
671671
*
672-
* >>> pl.readJSONStream(readStream).then(df => console.log(df));
672+
* >>> pl.readJSONStream(readStream, { format: "lines" }).then(df => console.log(df));
673673
* shape: (4, 2)
674674
* ┌─────┬─────┐
675675
* │ a ┆ b │

0 commit comments

Comments
 (0)