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

Class ArrayDataPrinter

cpp/gdb_arrow.py:1555–1641  ·  view source on GitHub ↗

Pretty-printer for arrow::ArrayData.

Source from the content-addressed store, hash-verified

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

Callers 2

to_stringMethod · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected