| 1526 | ] |
| 1527 | ) |
| 1528 | def test_table_basics(cls): |
| 1529 | data = [ |
| 1530 | pa.array(range(5), type='int16'), |
| 1531 | pa.array([-10, -5, 0, None, 10], type='int32') |
| 1532 | ] |
| 1533 | table = cls.from_arrays(data, names=('a', 'b')) |
| 1534 | table.validate() |
| 1535 | |
| 1536 | assert not table.schema.metadata |
| 1537 | assert len(table) == 5 |
| 1538 | assert table.num_rows == 5 |
| 1539 | assert table.num_columns == len(data) |
| 1540 | assert table.shape == (5, 2) |
| 1541 | # (only the second array has a null bitmap) |
| 1542 | assert table.get_total_buffer_size() == (5 * 2) + (5 * 4 + 1) |
| 1543 | assert table.nbytes == (5 * 2) + (5 * 4 + 1) |
| 1544 | assert sys.getsizeof(table) >= object.__sizeof__( |
| 1545 | table) + table.get_total_buffer_size() |
| 1546 | |
| 1547 | pydict = table.to_pydict() |
| 1548 | assert pydict == OrderedDict([ |
| 1549 | ('a', [0, 1, 2, 3, 4]), |
| 1550 | ('b', [-10, -5, 0, None, 10]) |
| 1551 | ]) |
| 1552 | assert isinstance(pydict, dict) |
| 1553 | assert table == cls.from_pydict(pydict, schema=table.schema) |
| 1554 | |
| 1555 | with pytest.raises(IndexError): |
| 1556 | # bounds checking |
| 1557 | table[2] |
| 1558 | |
| 1559 | columns = [] |
| 1560 | for col in table.itercolumns(): |
| 1561 | |
| 1562 | if cls is pa.Table: |
| 1563 | assert type(col) is pa.ChunkedArray |
| 1564 | |
| 1565 | for chunk in col.iterchunks(): |
| 1566 | assert chunk is not None |
| 1567 | |
| 1568 | with pytest.raises(IndexError): |
| 1569 | col.chunk(-1) |
| 1570 | |
| 1571 | with pytest.raises(IndexError): |
| 1572 | col.chunk(col.num_chunks) |
| 1573 | |
| 1574 | else: |
| 1575 | assert issubclass(type(col), pa.Array) |
| 1576 | |
| 1577 | columns.append(col) |
| 1578 | |
| 1579 | assert table.columns == columns |
| 1580 | assert table == cls.from_arrays(columns, names=table.column_names) |
| 1581 | assert table != cls.from_arrays(columns[1:], names=table.column_names[1:]) |
| 1582 | assert table != columns |
| 1583 | |
| 1584 | # Schema passed explicitly |
| 1585 | schema = pa.schema([pa.field('c0', pa.int16(), |