memory-graph 0.3.92__tar.gz → 0.3.94__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {memory_graph-0.3.92 → memory_graph-0.3.94}/PKG-INFO +12 -1
- {memory_graph-0.3.92 → memory_graph-0.3.94}/README.md +11 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/__init__.py +2 -2
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/config.py +3 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/config_default.py +8 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/extension_numpy.py +2 -1
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/html_table.py +1 -1
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/memory_to_nodes.py +17 -3
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/sequence.py +2 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/utils.py +13 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph.egg-info/PKG-INFO +12 -1
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph.egg-info/SOURCES.txt +1 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/pyproject.toml +1 -1
- memory_graph-0.3.94/setup.py +7 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/LICENSE.txt +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/call_stack.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/config_helpers.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/extension_pandas.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/extension_polars.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/extension_sqlite3.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/extension_torch.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/list_view.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/node_base.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/node_key_value.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/node_leaf.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/node_linear.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/node_table.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/slicer.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/slices.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/slices_iterator.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/slices_table_iterator.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/test.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/test_max_graph_depth.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/test_memory_graph.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/test_memory_to_nodes.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/test_sequence.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/test_slicer.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/test_slices.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph/test_slices_iterator.py +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph.egg-info/dependency_links.txt +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph.egg-info/requires.txt +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/memory_graph.egg-info/top_level.txt +0 -0
- {memory_graph-0.3.92 → memory_graph-0.3.94}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: memory_graph
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.94
|
|
4
4
|
Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
|
|
5
5
|
Author-email: Bas Terwijn <bterwijn@gmail.com>
|
|
6
6
|
License-Expression: BSD-2-Clause
|
|
@@ -1098,6 +1098,9 @@ Different aspects of memory_graph can be configured. The default configuration c
|
|
|
1098
1098
|
- ***mg.config.max_string_length*** : int
|
|
1099
1099
|
- The maximum length of strings shown in the graph. Longer strings will be truncated.
|
|
1100
1100
|
|
|
1101
|
+
- ***mg.config.precision*** : int
|
|
1102
|
+
- Round floats to this number of decimals, default None (no rouding).
|
|
1103
|
+
|
|
1101
1104
|
- ***mg.config.embedded_types*** : set[type]
|
|
1102
1105
|
- Holds all types for which no separate node is drawn but that are embedded in their parent Node.
|
|
1103
1106
|
|
|
@@ -1151,6 +1154,12 @@ Different aspects of memory_graph can be configured. The default configuration c
|
|
|
1151
1154
|
- **mg.transparent_background(b: bool = None)**
|
|
1152
1155
|
- Set transparent background to 'True' or 'False', or 'None' to toggle.
|
|
1153
1156
|
|
|
1157
|
+
- **mg.spline(splines: str = None)**
|
|
1158
|
+
- Set the graphviz 'splines' attribute (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), None restores the default.
|
|
1159
|
+
|
|
1160
|
+
- **mg.ranksep(ranksep: str = None)**
|
|
1161
|
+
- Set the graphviz 'ranksep' attribute (separation between ranks, say "2.0"), None restores the default.
|
|
1162
|
+
|
|
1154
1163
|
## Simplified Graph ##
|
|
1155
1164
|
Memory_graph simplifies the visualization (and the viewer's mental model) by **not** showing separate nodes for immutable types like `bool`, `int`, `float`, `complex`, and `str` by default. This simplification can sometimes be slightly misleading. As in the example below, after a shallow copy, lists `a` and `b` technically share their `int` values, but the graph makes it appear as though `a` and `b` each have their own copies. However, since `int` is immutable, this simplification will never lead to unexpected changes (changing `a`'s ints won’t affect `b`) so will never result in bugs.
|
|
1156
1165
|
|
|
@@ -1564,6 +1573,7 @@ import memory_graph as mg
|
|
|
1564
1573
|
import numpy as np
|
|
1565
1574
|
mg.extend_numpy()
|
|
1566
1575
|
np.random.seed(0) # use same random numbers each run
|
|
1576
|
+
mg.config.precision = 3 # round floats to just 3 decimals
|
|
1567
1577
|
|
|
1568
1578
|
matrix = np.matrix([[i*5+j for j in range(4)] for i in range(5)])
|
|
1569
1579
|
ndarray_1d = np.array([1.1, 2, 3, 4, 5])
|
|
@@ -1671,6 +1681,7 @@ conn.close()
|
|
|
1671
1681
|
```
|
|
1672
1682
|

|
|
1673
1683
|
|
|
1684
|
+
Or see this larger example in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=sqlite3&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph_examples/refs/heads/main/sqlite3_example.py×tep=0.2&play).
|
|
1674
1685
|
|
|
1675
1686
|
# Memory Graph Web Debugger #
|
|
1676
1687
|
The <a href="https://memory-graph.com/#play" target="_blank">Memory Graph Web Debugger</a> lets us use memory_graph without any installation.
|
|
@@ -1078,6 +1078,9 @@ Different aspects of memory_graph can be configured. The default configuration c
|
|
|
1078
1078
|
- ***mg.config.max_string_length*** : int
|
|
1079
1079
|
- The maximum length of strings shown in the graph. Longer strings will be truncated.
|
|
1080
1080
|
|
|
1081
|
+
- ***mg.config.precision*** : int
|
|
1082
|
+
- Round floats to this number of decimals, default None (no rouding).
|
|
1083
|
+
|
|
1081
1084
|
- ***mg.config.embedded_types*** : set[type]
|
|
1082
1085
|
- Holds all types for which no separate node is drawn but that are embedded in their parent Node.
|
|
1083
1086
|
|
|
@@ -1131,6 +1134,12 @@ Different aspects of memory_graph can be configured. The default configuration c
|
|
|
1131
1134
|
- **mg.transparent_background(b: bool = None)**
|
|
1132
1135
|
- Set transparent background to 'True' or 'False', or 'None' to toggle.
|
|
1133
1136
|
|
|
1137
|
+
- **mg.spline(splines: str = None)**
|
|
1138
|
+
- Set the graphviz 'splines' attribute (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), None restores the default.
|
|
1139
|
+
|
|
1140
|
+
- **mg.ranksep(ranksep: str = None)**
|
|
1141
|
+
- Set the graphviz 'ranksep' attribute (separation between ranks, say "2.0"), None restores the default.
|
|
1142
|
+
|
|
1134
1143
|
## Simplified Graph ##
|
|
1135
1144
|
Memory_graph simplifies the visualization (and the viewer's mental model) by **not** showing separate nodes for immutable types like `bool`, `int`, `float`, `complex`, and `str` by default. This simplification can sometimes be slightly misleading. As in the example below, after a shallow copy, lists `a` and `b` technically share their `int` values, but the graph makes it appear as though `a` and `b` each have their own copies. However, since `int` is immutable, this simplification will never lead to unexpected changes (changing `a`'s ints won’t affect `b`) so will never result in bugs.
|
|
1136
1145
|
|
|
@@ -1544,6 +1553,7 @@ import memory_graph as mg
|
|
|
1544
1553
|
import numpy as np
|
|
1545
1554
|
mg.extend_numpy()
|
|
1546
1555
|
np.random.seed(0) # use same random numbers each run
|
|
1556
|
+
mg.config.precision = 3 # round floats to just 3 decimals
|
|
1547
1557
|
|
|
1548
1558
|
matrix = np.matrix([[i*5+j for j in range(4)] for i in range(5)])
|
|
1549
1559
|
ndarray_1d = np.array([1.1, 2, 3, 4, 5])
|
|
@@ -1651,6 +1661,7 @@ conn.close()
|
|
|
1651
1661
|
```
|
|
1652
1662
|

|
|
1653
1663
|
|
|
1664
|
+
Or see this larger example in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=sqlite3&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph_examples/refs/heads/main/sqlite3_example.py×tep=0.2&play).
|
|
1654
1665
|
|
|
1655
1666
|
# Memory Graph Web Debugger #
|
|
1656
1667
|
The <a href="https://memory-graph.com/#play" target="_blank">Memory Graph Web Debugger</a> lets us use memory_graph without any installation.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# Copyright (c) 2023, Bas Terwijn.
|
|
3
3
|
# SPDX-License-Identifier: BSD-2-Clause
|
|
4
4
|
|
|
5
|
-
__version__ = "0.3.
|
|
5
|
+
__version__ = "0.3.94"
|
|
6
6
|
__author__ = 'Bas Terwijn'
|
|
7
7
|
|
|
8
8
|
import memory_graph.memory_to_nodes as memory_to_nodes
|
|
@@ -26,7 +26,7 @@ if not hasattr(builtins, "mg"):
|
|
|
26
26
|
builtins.mg = mg
|
|
27
27
|
|
|
28
28
|
# re-exports for shorter names
|
|
29
|
-
from .config_default import layout, dark_mode, transparent_background, set_colors
|
|
29
|
+
from .config_default import layout, spline, ranksep, dark_mode, transparent_background, set_colors
|
|
30
30
|
from .slicer import Slicer
|
|
31
31
|
from .node_leaf import Node_Leaf
|
|
32
32
|
from .node_linear import Node_Linear
|
|
@@ -115,6 +115,14 @@ def layout(horizontal = None):
|
|
|
115
115
|
else:
|
|
116
116
|
config.horizontal = horizontal
|
|
117
117
|
|
|
118
|
+
def spline(splines = None):
|
|
119
|
+
""" Set the graphviz 'splines' attribute (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), None restores the default. """
|
|
120
|
+
config.splines = 'spline' if splines is None else splines
|
|
121
|
+
|
|
122
|
+
def ranksep(ranksep = None):
|
|
123
|
+
""" Set the graphviz 'ranksep' attribute (separation between ranks in inches), None restores the default. """
|
|
124
|
+
config.ranksep = '0.5' if ranksep is None else str(ranksep)
|
|
125
|
+
|
|
118
126
|
def reset():
|
|
119
127
|
|
|
120
128
|
set_colors(config.color_mode_dark, config.transparent_background)
|
|
@@ -32,7 +32,8 @@ def extend_numpy():
|
|
|
32
32
|
import numpy as np
|
|
33
33
|
|
|
34
34
|
config.embedded_types |= get_numpy_immutables()
|
|
35
|
-
|
|
35
|
+
# np.asarray converts matrix to ndarray to avoid infinite recursion due to index issue
|
|
36
|
+
config.type_to_node[np.matrix] = lambda data : ndarray_to_node(data, np.asarray(data))
|
|
36
37
|
config.type_to_node[np.ndarray] = lambda data : ndarray_to_node(data, data)
|
|
37
38
|
|
|
38
39
|
config_default.type_to_color_light[np.ndarray] = "hotpink1"
|
|
@@ -9,7 +9,7 @@ import memory_graph.utils as utils
|
|
|
9
9
|
def format_string(value, quote_str):
|
|
10
10
|
""" Helper function to format 'value' to be shown in the graph. We escape html characters and convert newlines to <BR/> tags. """
|
|
11
11
|
to_string = config_helpers.get_to_string(value)
|
|
12
|
-
s = to_string(value)
|
|
12
|
+
s = to_string(utils.round_float(value, config.precision))
|
|
13
13
|
if quote_str and isinstance(value, (str, utils.full_str)):
|
|
14
14
|
s = utils.quote_string(s)
|
|
15
15
|
if not isinstance(value, utils.html_str): # <IMG> can't have padding in Graphviz
|
|
@@ -262,9 +262,23 @@ def memory_to_nodes(data):
|
|
|
262
262
|
id_to_slices = add_missing_edges(nodes, id_to_slices, config.max_missing_edges)
|
|
263
263
|
#print('id_to_slices:',id_to_slices)
|
|
264
264
|
embed_keys_in_key_value_nodes(nodes, nodes_key_value, id_to_slices)
|
|
265
|
-
graphviz_graph_attr = {'fontname': config.fontname,
|
|
266
|
-
|
|
267
|
-
|
|
265
|
+
graphviz_graph_attr = {'fontname': config.fontname,
|
|
266
|
+
'fontsize': config.fontsize,
|
|
267
|
+
'fontcolor': config.foreground_color,
|
|
268
|
+
'bgcolor': config.background_color,
|
|
269
|
+
'splines': str(config.splines),
|
|
270
|
+
'ranksep': str(config.ranksep),
|
|
271
|
+
}
|
|
272
|
+
graphviz_node_attr = {'fontname': config.fontname,
|
|
273
|
+
'fontsize': config.fontsize,
|
|
274
|
+
'shape': 'plaintext',
|
|
275
|
+
'fontcolor': config.foreground_color
|
|
276
|
+
}
|
|
277
|
+
graphviz_edge_attr = {'fontname': config.fontname,
|
|
278
|
+
'fontsize': config.fontsize,
|
|
279
|
+
'fontcolor': config.foreground_color,
|
|
280
|
+
'color': config.foreground_color
|
|
281
|
+
}
|
|
268
282
|
graphviz_graph=graphviz.Digraph('memory_graph',
|
|
269
283
|
graph_attr=graphviz_graph_attr,
|
|
270
284
|
node_attr=graphviz_node_attr,
|
|
@@ -55,6 +55,8 @@ class Sequence1D(Sequence):
|
|
|
55
55
|
return Slices1D()
|
|
56
56
|
|
|
57
57
|
def slice(self, slicer):
|
|
58
|
+
if type(slicer) is tuple: # (row, column) slicer for a type that is sometimes 1D, use the first
|
|
59
|
+
slicer = slicer[0]
|
|
58
60
|
return slicer.get_slices( len(self.data) )
|
|
59
61
|
|
|
60
62
|
def indices_all(self):
|
|
@@ -199,6 +199,19 @@ def my_round(value):
|
|
|
199
199
|
""" Rounds the value to the nearest integer rounding '.5' up consistantly. """
|
|
200
200
|
return math.floor(value + 0.5)
|
|
201
201
|
|
|
202
|
+
def round_float(value, precision):
|
|
203
|
+
""" Rounds float and complex values (including numpy scalars) to 'precision' digits after the decimal point, other values are returned unchanged. """
|
|
204
|
+
if precision is None:
|
|
205
|
+
return value
|
|
206
|
+
if isinstance(value, float):
|
|
207
|
+
return round(value, precision)
|
|
208
|
+
if isinstance(value, complex):
|
|
209
|
+
return complex(round(value.real, precision), round(value.imag, precision))
|
|
210
|
+
dtype = getattr(value, 'dtype', None)
|
|
211
|
+
if dtype is not None and dtype.kind in 'fc' and getattr(value, 'shape', None) == ():
|
|
212
|
+
return value.round(precision)
|
|
213
|
+
return value
|
|
214
|
+
|
|
202
215
|
def generator_has_data(generator):
|
|
203
216
|
""" Returns 'True' if the generator has data. """
|
|
204
217
|
try:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: memory_graph
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.94
|
|
4
4
|
Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
|
|
5
5
|
Author-email: Bas Terwijn <bterwijn@gmail.com>
|
|
6
6
|
License-Expression: BSD-2-Clause
|
|
@@ -1098,6 +1098,9 @@ Different aspects of memory_graph can be configured. The default configuration c
|
|
|
1098
1098
|
- ***mg.config.max_string_length*** : int
|
|
1099
1099
|
- The maximum length of strings shown in the graph. Longer strings will be truncated.
|
|
1100
1100
|
|
|
1101
|
+
- ***mg.config.precision*** : int
|
|
1102
|
+
- Round floats to this number of decimals, default None (no rouding).
|
|
1103
|
+
|
|
1101
1104
|
- ***mg.config.embedded_types*** : set[type]
|
|
1102
1105
|
- Holds all types for which no separate node is drawn but that are embedded in their parent Node.
|
|
1103
1106
|
|
|
@@ -1151,6 +1154,12 @@ Different aspects of memory_graph can be configured. The default configuration c
|
|
|
1151
1154
|
- **mg.transparent_background(b: bool = None)**
|
|
1152
1155
|
- Set transparent background to 'True' or 'False', or 'None' to toggle.
|
|
1153
1156
|
|
|
1157
|
+
- **mg.spline(splines: str = None)**
|
|
1158
|
+
- Set the graphviz 'splines' attribute (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), None restores the default.
|
|
1159
|
+
|
|
1160
|
+
- **mg.ranksep(ranksep: str = None)**
|
|
1161
|
+
- Set the graphviz 'ranksep' attribute (separation between ranks, say "2.0"), None restores the default.
|
|
1162
|
+
|
|
1154
1163
|
## Simplified Graph ##
|
|
1155
1164
|
Memory_graph simplifies the visualization (and the viewer's mental model) by **not** showing separate nodes for immutable types like `bool`, `int`, `float`, `complex`, and `str` by default. This simplification can sometimes be slightly misleading. As in the example below, after a shallow copy, lists `a` and `b` technically share their `int` values, but the graph makes it appear as though `a` and `b` each have their own copies. However, since `int` is immutable, this simplification will never lead to unexpected changes (changing `a`'s ints won’t affect `b`) so will never result in bugs.
|
|
1156
1165
|
|
|
@@ -1564,6 +1573,7 @@ import memory_graph as mg
|
|
|
1564
1573
|
import numpy as np
|
|
1565
1574
|
mg.extend_numpy()
|
|
1566
1575
|
np.random.seed(0) # use same random numbers each run
|
|
1576
|
+
mg.config.precision = 3 # round floats to just 3 decimals
|
|
1567
1577
|
|
|
1568
1578
|
matrix = np.matrix([[i*5+j for j in range(4)] for i in range(5)])
|
|
1569
1579
|
ndarray_1d = np.array([1.1, 2, 3, 4, 5])
|
|
@@ -1671,6 +1681,7 @@ conn.close()
|
|
|
1671
1681
|
```
|
|
1672
1682
|

|
|
1673
1683
|
|
|
1684
|
+
Or see this larger example in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=sqlite3&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph_examples/refs/heads/main/sqlite3_example.py×tep=0.2&play).
|
|
1674
1685
|
|
|
1675
1686
|
# Memory Graph Web Debugger #
|
|
1676
1687
|
The <a href="https://memory-graph.com/#play" target="_blank">Memory Graph Web Debugger</a> lets us use memory_graph without any installation.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "memory_graph"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.94"
|
|
8
8
|
description = "Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy."
|
|
9
9
|
authors = [
|
|
10
10
|
{name = "Bas Terwijn", email = "bterwijn@gmail.com"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|