MCPcopy
hub / github.com/huggingface/datasets / test_write_row

Function test_write_row

tests/test_arrow_writer.py:191–203  ·  view source on GitHub ↗
(fields, writer_batch_size)

Source from the content-addressed store, hash-verified

189 "fields", [None, {"col_1": pa.string(), "col_2": pa.int64()}, {"col_1": pa.string(), "col_2": pa.int32()}]
190)
191def test_write_row(fields, writer_batch_size):
192 output = pa.BufferOutputStream()
193 schema = pa.schema(fields) if fields else None
194 with ArrowWriter(stream=output, schema=schema, writer_batch_size=writer_batch_size) as writer:
195 writer.write_row(pa.Table.from_pydict({"col_1": ["foo"], "col_2": [1]}))
196 writer.write_row(pa.Table.from_pydict({"col_1": ["bar"], "col_2": [2]}))
197 num_examples, num_bytes = writer.finalize()
198 assert num_examples == 2
199 assert num_bytes > 0
200 if not fields:
201 fields = {"col_1": pa.string(), "col_2": pa.int64()}
202 assert writer._schema == pa.schema(fields, metadata=writer._schema.metadata)
203 _check_output(output.getvalue(), expected_num_chunks=num_examples if writer_batch_size == 1 else 1)
204
205
206def test_write_file():

Callers

nothing calls this directly

Calls 6

ArrowWriterClass · 0.90
_check_outputFunction · 0.85
write_rowMethod · 0.80
from_pydictMethod · 0.80
finalizeMethod · 0.80
schemaMethod · 0.45

Tested by

no test coverage detected