memory-graph 0.3.88__tar.gz → 0.3.90__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.
Files changed (41) hide show
  1. {memory_graph-0.3.88/memory_graph.egg-info → memory_graph-0.3.90}/PKG-INFO +32 -7
  2. memory_graph-0.3.88/PKG-INFO → memory_graph-0.3.90/README.md +31 -26
  3. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/__init__.py +24 -1
  4. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/config_default.py +5 -0
  5. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/utils.py +13 -0
  6. memory_graph-0.3.88/README.md → memory_graph-0.3.90/memory_graph.egg-info/PKG-INFO +51 -6
  7. {memory_graph-0.3.88 → memory_graph-0.3.90}/pyproject.toml +1 -1
  8. {memory_graph-0.3.88 → memory_graph-0.3.90}/LICENSE.txt +0 -0
  9. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/call_stack.py +0 -0
  10. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/config.py +0 -0
  11. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/config_helpers.py +0 -0
  12. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/extension_numpy.py +0 -0
  13. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/extension_pandas.py +0 -0
  14. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/extension_torch.py +0 -0
  15. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/html_table.py +0 -0
  16. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/list_view.py +0 -0
  17. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/memory_to_nodes.py +0 -0
  18. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/node_base.py +0 -0
  19. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/node_key_value.py +0 -0
  20. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/node_leaf.py +0 -0
  21. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/node_linear.py +0 -0
  22. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/node_table.py +0 -0
  23. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/sequence.py +0 -0
  24. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/slicer.py +0 -0
  25. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/slices.py +0 -0
  26. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/slices_iterator.py +0 -0
  27. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/slices_table_iterator.py +0 -0
  28. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/test.py +0 -0
  29. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/test_max_graph_depth.py +0 -0
  30. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/test_memory_graph.py +0 -0
  31. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/test_memory_to_nodes.py +0 -0
  32. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/test_sequence.py +0 -0
  33. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/test_slicer.py +0 -0
  34. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/test_slices.py +0 -0
  35. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph/test_slices_iterator.py +0 -0
  36. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph.egg-info/SOURCES.txt +0 -0
  37. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph.egg-info/dependency_links.txt +0 -0
  38. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph.egg-info/requires.txt +0 -0
  39. {memory_graph-0.3.88 → memory_graph-0.3.90}/memory_graph.egg-info/top_level.txt +0 -0
  40. {memory_graph-0.3.88 → memory_graph-0.3.90}/setup.cfg +0 -0
  41. {memory_graph-0.3.88 → memory_graph-0.3.90}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memory_graph
3
- Version: 0.3.88
3
+ Version: 0.3.90
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
@@ -1190,8 +1190,28 @@ mg.show(locals())
1190
1190
  ```
1191
1191
  ![avltree_fail.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/avltree_fail.png)
1192
1192
 
1193
- ## All attributes using dir() ##
1194
- A useful start is to give it some color, show the list of all its attributes using `dir()`, and setting an empty Slicer to see the attribute list in full.
1193
+ ## Show attributes using build_node() ##
1194
+ Then first give it some color, show its attributes using:
1195
+
1196
+ ```python
1197
+ mg.build_node(data)
1198
+ ```
1199
+
1200
+ optionally filter attributes using:
1201
+
1202
+ ```python
1203
+ mg.build_node(data,
1204
+ filters=[mg.filter_non_callable,
1205
+ mg.filter_non_dunder,
1206
+ mg.filter_non_underscore
1207
+ mg.filter_names({'left', 'right'}),
1208
+ lambda kvs : ((k,v) for k,v in kvs
1209
+ if k in {'left', 'right'} and
1210
+ not callable(v))
1211
+ ])
1212
+ ```
1213
+
1214
+ and set an empty Slicer to show all attributes even if the sequence is long.
1195
1215
 
1196
1216
  ```python
1197
1217
  import memory_graph as mg
@@ -1205,15 +1225,16 @@ tree.insert(20, "twenty")
1205
1225
  tree.insert(15, "fifteen")
1206
1226
 
1207
1227
  mg.config.type_to_color[bintrees.avltree.Node] = "sandybrown"
1208
- mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.Node_Linear(data,
1209
- dir(data))
1228
+ mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.build_node(data,
1229
+ filters=[mg.filter_non_dunder])
1210
1230
  mg.config.type_to_slicer[bintrees.avltree.Node] = mg.Slicer()
1211
1231
 
1212
1232
  mg.show(locals())
1213
1233
  ```
1214
- ![avltree_dir.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/avltree_dir.png)
1215
1234
 
1216
- Next figure out what the attributes are you want to graph and choose a Node type, there are four options:
1235
+ ![avltree_dir.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/avltree_non_dunder.png)
1236
+
1237
+ Next figure out what the attributes are you actually want to graph and choose a Node type, there are four options:
1217
1238
 
1218
1239
  ## 1) Node_Leaf ##
1219
1240
  Node_Leaf is a node with no children and shows just a single value.
@@ -1555,6 +1576,8 @@ mg.show(locals())
1555
1576
 
1556
1577
  Or see it in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=numpy&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/mg_numpy.py&play).
1557
1578
 
1579
+ See this [introduction to NumPy operations](https://memory-graph.com/#micropip=numpy&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/numpy_operations.py&timestep=0.5&play).
1580
+
1558
1581
  ## Pandas ##
1559
1582
  For pandas types `Series` and `DataFrame`, use `mg.extend_pandas()`:
1560
1583
 
@@ -1576,6 +1599,8 @@ mg.show(locals())
1576
1599
 
1577
1600
  Or see it in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=pandas&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/mg_pandas.py&play).
1578
1601
 
1602
+ See this [introduction to Pandas operations](https://memory-graph.com/#micropip=numpy&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/pandas_operations.py&timestep=0.5&play).
1603
+
1579
1604
  ## PyTorch ##
1580
1605
  For torch type `tensor`, use `mg.extend_torch()`:
1581
1606
 
@@ -1,23 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: memory_graph
3
- Version: 0.3.88
4
- Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
5
- Author-email: Bas Terwijn <bterwijn@gmail.com>
6
- License-Expression: BSD-2-Clause
7
- Project-URL: Homepage, https://github.com/bterwijn/memory_graph
8
- Project-URL: Repository, https://github.com/bterwijn/memory_graph.git
9
- Classifier: Development Status :: 4 - Beta
10
- Classifier: Intended Audience :: Education
11
- Classifier: Intended Audience :: Developers
12
- Classifier: Programming Language :: Python :: 3
13
- Classifier: Topic :: Education
14
- Classifier: Topic :: Software Development :: Debuggers
15
- Requires-Python: >=3.7
16
- Description-Content-Type: text/markdown
17
- License-File: LICENSE.txt
18
- Requires-Dist: graphviz
19
- Dynamic: license-file
20
-
21
1
  # Installation #
22
2
  Install (or upgrade) `memory_graph` using pip:
23
3
  ```
@@ -1190,8 +1170,28 @@ mg.show(locals())
1190
1170
  ```
1191
1171
  ![avltree_fail.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/avltree_fail.png)
1192
1172
 
1193
- ## All attributes using dir() ##
1194
- A useful start is to give it some color, show the list of all its attributes using `dir()`, and setting an empty Slicer to see the attribute list in full.
1173
+ ## Show attributes using build_node() ##
1174
+ Then first give it some color, show its attributes using:
1175
+
1176
+ ```python
1177
+ mg.build_node(data)
1178
+ ```
1179
+
1180
+ optionally filter attributes using:
1181
+
1182
+ ```python
1183
+ mg.build_node(data,
1184
+ filters=[mg.filter_non_callable,
1185
+ mg.filter_non_dunder,
1186
+ mg.filter_non_underscore
1187
+ mg.filter_names({'left', 'right'}),
1188
+ lambda kvs : ((k,v) for k,v in kvs
1189
+ if k in {'left', 'right'} and
1190
+ not callable(v))
1191
+ ])
1192
+ ```
1193
+
1194
+ and set an empty Slicer to show all attributes even if the sequence is long.
1195
1195
 
1196
1196
  ```python
1197
1197
  import memory_graph as mg
@@ -1205,15 +1205,16 @@ tree.insert(20, "twenty")
1205
1205
  tree.insert(15, "fifteen")
1206
1206
 
1207
1207
  mg.config.type_to_color[bintrees.avltree.Node] = "sandybrown"
1208
- mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.Node_Linear(data,
1209
- dir(data))
1208
+ mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.build_node(data,
1209
+ filters=[mg.filter_non_dunder])
1210
1210
  mg.config.type_to_slicer[bintrees.avltree.Node] = mg.Slicer()
1211
1211
 
1212
1212
  mg.show(locals())
1213
1213
  ```
1214
- ![avltree_dir.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/avltree_dir.png)
1215
1214
 
1216
- Next figure out what the attributes are you want to graph and choose a Node type, there are four options:
1215
+ ![avltree_dir.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/avltree_non_dunder.png)
1216
+
1217
+ Next figure out what the attributes are you actually want to graph and choose a Node type, there are four options:
1217
1218
 
1218
1219
  ## 1) Node_Leaf ##
1219
1220
  Node_Leaf is a node with no children and shows just a single value.
@@ -1555,6 +1556,8 @@ mg.show(locals())
1555
1556
 
1556
1557
  Or see it in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=numpy&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/mg_numpy.py&play).
1557
1558
 
1559
+ See this [introduction to NumPy operations](https://memory-graph.com/#micropip=numpy&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/numpy_operations.py&timestep=0.5&play).
1560
+
1558
1561
  ## Pandas ##
1559
1562
  For pandas types `Series` and `DataFrame`, use `mg.extend_pandas()`:
1560
1563
 
@@ -1576,6 +1579,8 @@ mg.show(locals())
1576
1579
 
1577
1580
  Or see it in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=pandas&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/mg_pandas.py&play).
1578
1581
 
1582
+ See this [introduction to Pandas operations](https://memory-graph.com/#micropip=numpy&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/pandas_operations.py&timestep=0.5&play).
1583
+
1579
1584
  ## PyTorch ##
1580
1585
  For torch type `tensor`, use `mg.extend_torch()`:
1581
1586
 
@@ -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.88"
5
+ __version__ = "0.3.90"
6
6
  __author__ = 'Bas Terwijn'
7
7
 
8
8
  import memory_graph.memory_to_nodes as memory_to_nodes
@@ -537,3 +537,26 @@ def collapse_type(type_name):
537
537
  def reset_type(type_name):
538
538
  del mg.config.type_to_node[type_name]
539
539
  del mg.config.type_to_color[type_name]
540
+
541
+ # ------------ atributes to Node_Key_Value
542
+
543
+ def build_node(data, filters=None):
544
+ attr_values = ((attr, utils.safe_getattr(data, attr)) for attr in dir(data))
545
+ if filters is not None:
546
+ for filter in filters:
547
+ attr_values = filter(attr_values)
548
+ return Node_Key_Value(data, ((attr, value)
549
+ for attr, value in attr_values
550
+ if value is not utils.SENTINEL
551
+ ))
552
+
553
+ def filter_non_callable(tuples):
554
+ return ((k,v) for k, v in tuples if not callable(v))
555
+ def filter_non_dunder(tuples):
556
+ return ((k,v) for k, v in tuples if not k.startswith('__'))
557
+ def filter_non_underscore(tuples):
558
+ return ((k,v) for k, v in tuples if not k.startswith('_'))
559
+ def filter_names(names):
560
+ def filter(tuples):
561
+ return ((k,v) for k, v in tuples if k in names)
562
+ return filter
@@ -179,6 +179,11 @@ def reset():
179
179
  call_stack: lambda data: Node_Key_Value(data, data.items()),
180
180
  type: lambda data: Node_Key_Value(data, utils.filter_type_attributes(vars(data).items())),
181
181
  range: lambda data: Node_Key_Value(data, {'start':data.start, 'stop':data.stop, 'step':data.step}.items()),
182
+ tuple: lambda data: (
183
+ Node_Key_Value(data, zip(data._fields, iter(data)))
184
+ if utils.is_namedtuple(data) else
185
+ Node_Linear(data, iter(data))
186
+ ),
182
187
  dict: lambda data: (
183
188
  Node_Key_Value(data, utils.filter_dict(data) )
184
189
  if dict in config.embedding_types else
@@ -11,6 +11,14 @@ import html
11
11
 
12
12
  import memory_graph.config as config
13
13
 
14
+ SENTINEL = object()
15
+
16
+ def safe_getattr(obj, attr):
17
+ try:
18
+ return getattr(obj, attr, SENTINEL)
19
+ except Exception:
20
+ return SENTINEL
21
+
14
22
  class Base_Str():
15
23
  def __init__(self, s):
16
24
  self.s = s
@@ -165,6 +173,10 @@ def is_finite_iterable(data):
165
173
  return True
166
174
  except TypeError:
167
175
  return False
176
+
177
+ def is_namedtuple(data):
178
+ """ Returns 'True' if 'data' is a namedtuple. """
179
+ return isinstance(data, tuple) and hasattr(data, '_fields')
168
180
 
169
181
  def get_type_name(data):
170
182
  """ Returns the name of the type of 'data'. """
@@ -194,3 +206,4 @@ def generator_has_data(generator):
194
206
  return True
195
207
  except StopIteration:
196
208
  return False
209
+
@@ -1,3 +1,23 @@
1
+ Metadata-Version: 2.4
2
+ Name: memory_graph
3
+ Version: 0.3.90
4
+ Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
5
+ Author-email: Bas Terwijn <bterwijn@gmail.com>
6
+ License-Expression: BSD-2-Clause
7
+ Project-URL: Homepage, https://github.com/bterwijn/memory_graph
8
+ Project-URL: Repository, https://github.com/bterwijn/memory_graph.git
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Education
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Education
14
+ Classifier: Topic :: Software Development :: Debuggers
15
+ Requires-Python: >=3.7
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE.txt
18
+ Requires-Dist: graphviz
19
+ Dynamic: license-file
20
+
1
21
  # Installation #
2
22
  Install (or upgrade) `memory_graph` using pip:
3
23
  ```
@@ -1170,8 +1190,28 @@ mg.show(locals())
1170
1190
  ```
1171
1191
  ![avltree_fail.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/avltree_fail.png)
1172
1192
 
1173
- ## All attributes using dir() ##
1174
- A useful start is to give it some color, show the list of all its attributes using `dir()`, and setting an empty Slicer to see the attribute list in full.
1193
+ ## Show attributes using build_node() ##
1194
+ Then first give it some color, show its attributes using:
1195
+
1196
+ ```python
1197
+ mg.build_node(data)
1198
+ ```
1199
+
1200
+ optionally filter attributes using:
1201
+
1202
+ ```python
1203
+ mg.build_node(data,
1204
+ filters=[mg.filter_non_callable,
1205
+ mg.filter_non_dunder,
1206
+ mg.filter_non_underscore
1207
+ mg.filter_names({'left', 'right'}),
1208
+ lambda kvs : ((k,v) for k,v in kvs
1209
+ if k in {'left', 'right'} and
1210
+ not callable(v))
1211
+ ])
1212
+ ```
1213
+
1214
+ and set an empty Slicer to show all attributes even if the sequence is long.
1175
1215
 
1176
1216
  ```python
1177
1217
  import memory_graph as mg
@@ -1185,15 +1225,16 @@ tree.insert(20, "twenty")
1185
1225
  tree.insert(15, "fifteen")
1186
1226
 
1187
1227
  mg.config.type_to_color[bintrees.avltree.Node] = "sandybrown"
1188
- mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.Node_Linear(data,
1189
- dir(data))
1228
+ mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.build_node(data,
1229
+ filters=[mg.filter_non_dunder])
1190
1230
  mg.config.type_to_slicer[bintrees.avltree.Node] = mg.Slicer()
1191
1231
 
1192
1232
  mg.show(locals())
1193
1233
  ```
1194
- ![avltree_dir.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/avltree_dir.png)
1195
1234
 
1196
- Next figure out what the attributes are you want to graph and choose a Node type, there are four options:
1235
+ ![avltree_dir.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/avltree_non_dunder.png)
1236
+
1237
+ Next figure out what the attributes are you actually want to graph and choose a Node type, there are four options:
1197
1238
 
1198
1239
  ## 1) Node_Leaf ##
1199
1240
  Node_Leaf is a node with no children and shows just a single value.
@@ -1535,6 +1576,8 @@ mg.show(locals())
1535
1576
 
1536
1577
  Or see it in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=numpy&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/mg_numpy.py&play).
1537
1578
 
1579
+ See this [introduction to NumPy operations](https://memory-graph.com/#micropip=numpy&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/numpy_operations.py&timestep=0.5&play).
1580
+
1538
1581
  ## Pandas ##
1539
1582
  For pandas types `Series` and `DataFrame`, use `mg.extend_pandas()`:
1540
1583
 
@@ -1556,6 +1599,8 @@ mg.show(locals())
1556
1599
 
1557
1600
  Or see it in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=pandas&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/mg_pandas.py&play).
1558
1601
 
1602
+ See this [introduction to Pandas operations](https://memory-graph.com/#micropip=numpy&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/pandas_operations.py&timestep=0.5&play).
1603
+
1559
1604
  ## PyTorch ##
1560
1605
  For torch type `tensor`, use `mg.extend_torch()`:
1561
1606
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "memory_graph"
7
- version = "0.3.88"
7
+ version = "0.3.90"
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