MCPcopy Create free account
hub / github.com/apache/arrow / test_table_from_pydict_arrow_arrays

Function test_table_from_pydict_arrow_arrays

python/pyarrow/tests/test_table.py:2453–2480  ·  view source on GitHub ↗
(data, klass)

Source from the content-addressed store, hash-verified

2451 (([[''], ['foo', 'bar']], [[4.5], [5., None]]), pa.chunked_array),
2452])
2453def test_table_from_pydict_arrow_arrays(data, klass):
2454 data = OrderedDict([('strs', klass(data[0])), ('floats', klass(data[1]))])
2455 schema = pa.schema([('strs', pa.utf8()), ('floats', pa.float64())])
2456
2457 # With arrays as values
2458 table = pa.Table.from_pydict(data)
2459 assert table.num_columns == 2
2460 assert table.num_rows == 3
2461 assert table.schema == schema
2462
2463 # With explicit (matching) schema
2464 table = pa.Table.from_pydict(data, schema=schema)
2465 assert table.num_columns == 2
2466 assert table.num_rows == 3
2467 assert table.schema == schema
2468
2469 # with different but compatible schema
2470 schema = pa.schema([('strs', pa.utf8()), ('floats', pa.float32())])
2471 table = pa.Table.from_pydict(data, schema=schema)
2472 assert pa.types.is_float32(table.column('floats').type)
2473 assert table.num_columns == 2
2474 assert table.num_rows == 3
2475 assert table.schema == schema
2476
2477 # with different and incompatible schema
2478 schema = pa.schema([('strs', pa.utf8()), ('floats', pa.timestamp('s'))])
2479 with pytest.raises((NotImplementedError, TypeError)):
2480 pa.Table.from_pydict(data, schema=schema)
2481
2482
2483@pytest.mark.parametrize('data, klass', [

Callers

nothing calls this directly

Calls 2

schemaMethod · 0.45
columnMethod · 0.45

Tested by

no test coverage detected