MCPcopy Create free account
hub / github.com/bterwijn/memory_graph / Node_Table

Class Node_Table

memory_graph/node_table.py:11–84  ·  view source on GitHub ↗

Node_Table (subclass of Node_Base) is a node that represents a 2D table of data used for example for Numpy arrays and Pandas DataFrames.

Source from the content-addressed store, hash-verified

9import memory_graph.config as config
10import memory_graph.utils as utils
11
12class Node_Table(Node_Base):
13 """
14 Node_Table (subclass of Node_Base) is a node that represents a 2D table of data used for
15 example for Numpy arrays and Pandas DataFrames.
16 """
17
18 def __init__(self, data, children, data_width=None, row_names=None, col_names=None):
19 """
20 Create a Node_Table object. Use a Slicer to slice the children so the Node_Base
21 will not get to big or have too many childeren in the graph.
22 """
23 self.row_names = row_names
24 self.col_names = col_names
25 if data_width is None:
26 super().__init__(data, Sequence2D(children))
27 else:
28 list_views = [List_View(children, i, i+data_width) for i in range(0,len(children),data_width)]
29 super().__init__(data, Sequence2D(list_views))
30
31 def add_index_or_name(self, html_table, index, names):
32 if not names is None and index < len(names):
33 html_table.add_value(names[index], rounded=1, border=1)
34 else:
35 html_table.add_index(index)
36
37 def fill_html_table(self, nodes, html_table, slices, id_to_slices):
38 """
39 Fill the html_table with the children of the Node_Base.
40 """
41 if slices is None or slices.is_empty():
42 return
43 children = self.children
44 children_size = children.size()
45 children_width = children_size[1]
46 col_slices = slices.get_col_slices()
47
48 # Better keep a table in normal order, I think
49 #if config.horizontal:
50 # html_table.reverse_rows()
51
52 # use column indices for header row
53 html_table.add_value(utils.unquoted_str(''), border=0)
54 for coli in col_slices.table_iter(children_width):
55 if coli == -1:
56 html_table.add_value(utils.unquoted_str(''), border=0)
57 else:
58 self.add_index_or_name(html_table, coli, self.col_names)
59 html_table.add_new_line()
60
61 # add remaing rows
62 first_col = True
63 for index in slices.table_iter(children_size):
64 rowi, coli = index
65 if first_col and not coli==-3:
66 first_col = False
67 self.add_index_or_name(html_table, rowi, self.row_names)
68 if coli == -1:

Callers 4

test_tableFunction · 0.90
ndarray_to_nodeFunction · 0.90
extend_numpyFunction · 0.90
extend_pandasFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_tableFunction · 0.72