| 1465 | ] |
| 1466 | ) |
| 1467 | def test_table_basics(cls): |
| 1468 | data = [ |
| 1469 | pa.array(range(5), type='int16'), |
| 1470 | pa.array([-10, -5, 0, None, 10], type='int32') |
| 1471 | ] |
| 1472 | table = cls.from_arrays(data, names=('a', 'b')) |
| 1473 | table.validate() |
| 1474 | |
| 1475 | assert not table.schema.metadata |
| 1476 | assert len(table) == 5 |
| 1477 | assert table.num_rows == 5 |
| 1478 | assert table.num_columns == len(data) |
| 1479 | assert table.shape == (5, 2) |
| 1480 | # (only the second array has a null bitmap) |
| 1481 | assert table.get_total_buffer_size() == (5 * 2) + (5 * 4 + 1) |
| 1482 | assert table.nbytes == (5 * 2) + (5 * 4 + 1) |
| 1483 | assert sys.getsizeof(table) >= object.__sizeof__( |
| 1484 | table) + table.get_total_buffer_size() |
| 1485 | |
| 1486 | pydict = table.to_pydict() |
| 1487 | assert pydict == OrderedDict([ |
| 1488 | ('a', [0, 1, 2, 3, 4]), |
| 1489 | ('b', [-10, -5, 0, None, 10]) |
| 1490 | ]) |
| 1491 | assert isinstance(pydict, dict) |
| 1492 | assert table == cls.from_pydict(pydict, schema=table.schema) |
| 1493 | |
| 1494 | with pytest.raises(IndexError): |
| 1495 | # bounds checking |
| 1496 | table[2] |
| 1497 | |
| 1498 | columns = [] |
| 1499 | for col in table.itercolumns(): |
| 1500 | |
| 1501 | if cls is pa.Table: |
| 1502 | assert type(col) is pa.ChunkedArray |
| 1503 | |
| 1504 | for chunk in col.iterchunks(): |
| 1505 | assert chunk is not None |
| 1506 | |
| 1507 | with pytest.raises(IndexError): |
| 1508 | col.chunk(-1) |
| 1509 | |
| 1510 | with pytest.raises(IndexError): |
| 1511 | col.chunk(col.num_chunks) |
| 1512 | |
| 1513 | else: |
| 1514 | assert issubclass(type(col), pa.Array) |
| 1515 | |
| 1516 | columns.append(col) |
| 1517 | |
| 1518 | assert table.columns == columns |
| 1519 | assert table == cls.from_arrays(columns, names=table.column_names) |
| 1520 | assert table != cls.from_arrays(columns[1:], names=table.column_names[1:]) |
| 1521 | assert table != columns |
| 1522 | |
| 1523 | # Schema passed explicitly |
| 1524 | schema = pa.schema([pa.field('c0', pa.int16(), |