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

Function test_union_from_dense

python/pyarrow/tests/test_array.py:1485–1556  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1483
1484
1485def test_union_from_dense():
1486 binary = pa.array([b'a', b'b', b'c', b'd'], type='binary')
1487 int64 = pa.array([1, 2, 3], type='int64')
1488 types = pa.array([0, 1, 0, 0, 1, 1, 0], type='int8')
1489 logical_types = pa.array([11, 13, 11, 11, 13, 13, 11], type='int8')
1490 value_offsets = pa.array([0, 0, 1, 2, 1, 2, 3], type='int32')
1491 py_value = [b'a', 1, b'b', b'c', 2, 3, b'd']
1492
1493 def check_result(result, expected_field_names, expected_type_codes,
1494 expected_type_code_values):
1495 result.validate(full=True)
1496 actual_field_names = [result.type[i].name
1497 for i in range(result.type.num_fields)]
1498 assert actual_field_names == expected_field_names
1499 assert result.type.mode == "dense"
1500 assert result.type.type_codes == expected_type_codes
1501 assert result.to_pylist() == py_value
1502 assert expected_type_code_values.equals(result.type_codes)
1503 assert value_offsets.equals(result.offsets)
1504 assert result.field(0).equals(binary)
1505 assert result.field(1).equals(int64)
1506 with pytest.raises(KeyError):
1507 result.field(-1)
1508 with pytest.raises(KeyError):
1509 result.field(2)
1510
1511 # without field names and type codes
1512 check_result(pa.UnionArray.from_dense(types, value_offsets,
1513 [binary, int64]),
1514 expected_field_names=['0', '1'],
1515 expected_type_codes=[0, 1],
1516 expected_type_code_values=types)
1517
1518 # with field names
1519 check_result(pa.UnionArray.from_dense(types, value_offsets,
1520 [binary, int64],
1521 ['bin', 'int']),
1522 expected_field_names=['bin', 'int'],
1523 expected_type_codes=[0, 1],
1524 expected_type_code_values=types)
1525
1526 # with type codes
1527 check_result(pa.UnionArray.from_dense(logical_types, value_offsets,
1528 [binary, int64],
1529 type_codes=[11, 13]),
1530 expected_field_names=['0', '1'],
1531 expected_type_codes=[11, 13],
1532 expected_type_code_values=logical_types)
1533
1534 # with field names and type codes
1535 check_result(pa.UnionArray.from_dense(logical_types, value_offsets,
1536 [binary, int64],
1537 ['bin', 'int'], [11, 13]),
1538 expected_field_names=['bin', 'int'],
1539 expected_type_codes=[11, 13],
1540 expected_type_code_values=logical_types)
1541
1542 # Bad type ids

Callers

nothing calls this directly

Calls 3

check_resultFunction · 0.85
arrayMethod · 0.45
validateMethod · 0.45

Tested by

no test coverage detected