Pretty-printer for arrow::ArrayData.
| 1536 | |
| 1537 | |
| 1538 | class ArrayDataPrinter: |
| 1539 | """ |
| 1540 | Pretty-printer for arrow::ArrayData. |
| 1541 | """ |
| 1542 | |
| 1543 | def __new__(cls, name, val): |
| 1544 | # Lookup actual (derived) class to instantiate |
| 1545 | type_id = int(deref(val['type'])['id_']) |
| 1546 | type_class = lookup_type_class(type_id) |
| 1547 | if type_class is not None: |
| 1548 | cls = type_class.array_data_printer |
| 1549 | assert issubclass(cls, ArrayDataPrinter) |
| 1550 | self = object.__new__(cls) |
| 1551 | self.name = name |
| 1552 | self.val = val |
| 1553 | self.type_class = type_class |
| 1554 | self.type_name = type_class.name |
| 1555 | self.type_id = type_id |
| 1556 | self.offset = int(self.val['offset']) |
| 1557 | self.length = int(self.val['length']) |
| 1558 | return self |
| 1559 | |
| 1560 | @property |
| 1561 | def type(self): |
| 1562 | """ |
| 1563 | The concrete DataTypeClass instance. |
| 1564 | """ |
| 1565 | concrete_type = gdb.lookup_type(f"arrow::{self.type_name}") |
| 1566 | return cast_to_concrete(deref(self.val['type']), concrete_type) |
| 1567 | |
| 1568 | def _format_contents(self): |
| 1569 | return (f"length {self.length}, " |
| 1570 | f"offset {self.offset}, " |
| 1571 | f"{format_null_count(self.val['null_count'])}") |
| 1572 | |
| 1573 | def _buffer(self, index, type_id=None): |
| 1574 | buffers = StdVector(self.val['buffers']) |
| 1575 | bufptr = SharedPtr(buffers[index]).get() |
| 1576 | if int(bufptr) == 0: |
| 1577 | return None |
| 1578 | if type_id is not None: |
| 1579 | return TypedBuffer.from_type_id(bufptr.dereference(), type_id) |
| 1580 | else: |
| 1581 | return Buffer(bufptr.dereference()) |
| 1582 | |
| 1583 | def _buffer_values(self, index, type_id, length=None): |
| 1584 | """ |
| 1585 | Return a typed view of values in the buffer with the given index. |
| 1586 | |
| 1587 | Values are returned as tuples since some types may decode to |
| 1588 | multiple values (for example day_time_interval). |
| 1589 | """ |
| 1590 | buf = self._buffer(index, type_id) |
| 1591 | if buf is None: |
| 1592 | return None |
| 1593 | if length is None: |
| 1594 | length = self.length |
| 1595 | return buf.view(self.offset, length) |