memory-graph 0.3.90__tar.gz → 0.3.92__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.90 → memory_graph-0.3.92}/PKG-INFO +61 -7
- {memory_graph-0.3.90 → memory_graph-0.3.92}/README.md +60 -6
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/__init__.py +14 -1
- memory_graph-0.3.92/memory_graph/extension_polars.py +30 -0
- memory_graph-0.3.92/memory_graph/extension_sqlite3.py +119 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph.egg-info/PKG-INFO +61 -7
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph.egg-info/SOURCES.txt +2 -1
- {memory_graph-0.3.90 → memory_graph-0.3.92}/pyproject.toml +1 -1
- memory_graph-0.3.90/setup.py +0 -7
- {memory_graph-0.3.90 → memory_graph-0.3.92}/LICENSE.txt +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/call_stack.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/config.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/config_default.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/config_helpers.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/extension_numpy.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/extension_pandas.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/extension_torch.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/html_table.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/list_view.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/memory_to_nodes.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/node_base.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/node_key_value.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/node_leaf.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/node_linear.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/node_table.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/sequence.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/slicer.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/slices.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/slices_iterator.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/slices_table_iterator.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/test.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/test_max_graph_depth.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/test_memory_graph.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/test_memory_to_nodes.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/test_sequence.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/test_slicer.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/test_slices.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/test_slices_iterator.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph/utils.py +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph.egg-info/dependency_links.txt +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph.egg-info/requires.txt +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/memory_graph.egg-info/top_level.txt +0 -0
- {memory_graph-0.3.90 → memory_graph-0.3.92}/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.92
|
|
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
|
|
@@ -1556,8 +1556,8 @@ mg.show(locals())
|
|
|
1556
1556
|
# Extensions #
|
|
1557
1557
|
Different extensions are available for types from other Python packages.
|
|
1558
1558
|
|
|
1559
|
-
##
|
|
1560
|
-
For
|
|
1559
|
+
## NumPy ##
|
|
1560
|
+
For NumPy types `array` and `matrix` and `ndarray`, use `mg.extend_numpy()`:
|
|
1561
1561
|
|
|
1562
1562
|
```python
|
|
1563
1563
|
import memory_graph as mg
|
|
@@ -1574,12 +1574,12 @@ mg.show(locals())
|
|
|
1574
1574
|
```
|
|
1575
1575
|

|
|
1576
1576
|
|
|
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).
|
|
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×tep=0.5&play).
|
|
1578
1578
|
|
|
1579
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×tep=0.5&play).
|
|
1580
1580
|
|
|
1581
1581
|
## Pandas ##
|
|
1582
|
-
For
|
|
1582
|
+
For Pandas types `Series` and `DataFrame`, use `mg.extend_pandas()`:
|
|
1583
1583
|
|
|
1584
1584
|
```python
|
|
1585
1585
|
import memory_graph as mg
|
|
@@ -1597,9 +1597,30 @@ mg.show(locals())
|
|
|
1597
1597
|
```
|
|
1598
1598
|

|
|
1599
1599
|
|
|
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).
|
|
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×tep=0.5&play).
|
|
1601
|
+
|
|
1602
|
+
See this [introduction to Pandas operations](https://memory-graph.com/#micropip=numpy,pandas&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/pandas_operations.py×tep=0.5&play).
|
|
1603
|
+
|
|
1604
|
+
## Polars ##
|
|
1605
|
+
For Polars types `DataFrame`, use `mg.extend_polars()`:
|
|
1606
|
+
|
|
1607
|
+
```python
|
|
1608
|
+
import memory_graph as mg
|
|
1609
|
+
import polars as pl
|
|
1610
|
+
mg.extend_polars()
|
|
1611
|
+
|
|
1612
|
+
df = pl.DataFrame(
|
|
1613
|
+
{
|
|
1614
|
+
"name": ["Alice Archer", "Ben Brown", "Chloe Cooper", "Daniel Donovan"],
|
|
1615
|
+
"weight": [57.9, 72.5, 53.6, 83.1], # (kg)
|
|
1616
|
+
"height": [1.56, 1.77, 1.65, 1.75], # (m)
|
|
1617
|
+
}
|
|
1618
|
+
)
|
|
1619
|
+
|
|
1620
|
+
mg.show(locals())
|
|
1621
|
+
```
|
|
1622
|
+

|
|
1601
1623
|
|
|
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×tep=0.5&play).
|
|
1603
1624
|
|
|
1604
1625
|
## PyTorch ##
|
|
1605
1626
|
For torch type `tensor`, use `mg.extend_torch()`:
|
|
@@ -1618,6 +1639,39 @@ mg.show(locals())
|
|
|
1618
1639
|
```
|
|
1619
1640
|

|
|
1620
1641
|
|
|
1642
|
+
## SQLite3 ##
|
|
1643
|
+
For sqlite3 use `mg.extend_sqlite3()`:
|
|
1644
|
+
|
|
1645
|
+
```python
|
|
1646
|
+
import memory_graph as mg
|
|
1647
|
+
import sqlite3
|
|
1648
|
+
mg.extend_sqlite3()
|
|
1649
|
+
|
|
1650
|
+
conn = sqlite3.connect(":memory:")
|
|
1651
|
+
|
|
1652
|
+
conn.executescript("""
|
|
1653
|
+
CREATE TABLE students (
|
|
1654
|
+
id INTEGER PRIMARY KEY,
|
|
1655
|
+
name TEXT NOT NULL,
|
|
1656
|
+
age INTEGER
|
|
1657
|
+
);
|
|
1658
|
+
""")
|
|
1659
|
+
|
|
1660
|
+
conn.executemany(
|
|
1661
|
+
"INSERT INTO students VALUES (?, ?, ?)",
|
|
1662
|
+
[
|
|
1663
|
+
(1, "Alice", 20),
|
|
1664
|
+
(2, "Bob", 21),
|
|
1665
|
+
(3, "Charlie", 22),
|
|
1666
|
+
]
|
|
1667
|
+
)
|
|
1668
|
+
|
|
1669
|
+
mg.show(locals())
|
|
1670
|
+
conn.close()
|
|
1671
|
+
```
|
|
1672
|
+

|
|
1673
|
+
|
|
1674
|
+
|
|
1621
1675
|
# Memory Graph Web Debugger #
|
|
1622
1676
|
The <a href="https://memory-graph.com/#play" target="_blank">Memory Graph Web Debugger</a> lets us use memory_graph without any installation.
|
|
1623
1677
|

|
|
@@ -1536,8 +1536,8 @@ mg.show(locals())
|
|
|
1536
1536
|
# Extensions #
|
|
1537
1537
|
Different extensions are available for types from other Python packages.
|
|
1538
1538
|
|
|
1539
|
-
##
|
|
1540
|
-
For
|
|
1539
|
+
## NumPy ##
|
|
1540
|
+
For NumPy types `array` and `matrix` and `ndarray`, use `mg.extend_numpy()`:
|
|
1541
1541
|
|
|
1542
1542
|
```python
|
|
1543
1543
|
import memory_graph as mg
|
|
@@ -1554,12 +1554,12 @@ mg.show(locals())
|
|
|
1554
1554
|
```
|
|
1555
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
|
+
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×tep=0.5&play).
|
|
1558
1558
|
|
|
1559
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×tep=0.5&play).
|
|
1560
1560
|
|
|
1561
1561
|
## Pandas ##
|
|
1562
|
-
For
|
|
1562
|
+
For Pandas types `Series` and `DataFrame`, use `mg.extend_pandas()`:
|
|
1563
1563
|
|
|
1564
1564
|
```python
|
|
1565
1565
|
import memory_graph as mg
|
|
@@ -1577,9 +1577,30 @@ mg.show(locals())
|
|
|
1577
1577
|
```
|
|
1578
1578
|

|
|
1579
1579
|
|
|
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).
|
|
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×tep=0.5&play).
|
|
1581
|
+
|
|
1582
|
+
See this [introduction to Pandas operations](https://memory-graph.com/#micropip=numpy,pandas&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/pandas_operations.py×tep=0.5&play).
|
|
1583
|
+
|
|
1584
|
+
## Polars ##
|
|
1585
|
+
For Polars types `DataFrame`, use `mg.extend_polars()`:
|
|
1586
|
+
|
|
1587
|
+
```python
|
|
1588
|
+
import memory_graph as mg
|
|
1589
|
+
import polars as pl
|
|
1590
|
+
mg.extend_polars()
|
|
1591
|
+
|
|
1592
|
+
df = pl.DataFrame(
|
|
1593
|
+
{
|
|
1594
|
+
"name": ["Alice Archer", "Ben Brown", "Chloe Cooper", "Daniel Donovan"],
|
|
1595
|
+
"weight": [57.9, 72.5, 53.6, 83.1], # (kg)
|
|
1596
|
+
"height": [1.56, 1.77, 1.65, 1.75], # (m)
|
|
1597
|
+
}
|
|
1598
|
+
)
|
|
1599
|
+
|
|
1600
|
+
mg.show(locals())
|
|
1601
|
+
```
|
|
1602
|
+

|
|
1581
1603
|
|
|
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×tep=0.5&play).
|
|
1583
1604
|
|
|
1584
1605
|
## PyTorch ##
|
|
1585
1606
|
For torch type `tensor`, use `mg.extend_torch()`:
|
|
@@ -1598,6 +1619,39 @@ mg.show(locals())
|
|
|
1598
1619
|
```
|
|
1599
1620
|

|
|
1600
1621
|
|
|
1622
|
+
## SQLite3 ##
|
|
1623
|
+
For sqlite3 use `mg.extend_sqlite3()`:
|
|
1624
|
+
|
|
1625
|
+
```python
|
|
1626
|
+
import memory_graph as mg
|
|
1627
|
+
import sqlite3
|
|
1628
|
+
mg.extend_sqlite3()
|
|
1629
|
+
|
|
1630
|
+
conn = sqlite3.connect(":memory:")
|
|
1631
|
+
|
|
1632
|
+
conn.executescript("""
|
|
1633
|
+
CREATE TABLE students (
|
|
1634
|
+
id INTEGER PRIMARY KEY,
|
|
1635
|
+
name TEXT NOT NULL,
|
|
1636
|
+
age INTEGER
|
|
1637
|
+
);
|
|
1638
|
+
""")
|
|
1639
|
+
|
|
1640
|
+
conn.executemany(
|
|
1641
|
+
"INSERT INTO students VALUES (?, ?, ?)",
|
|
1642
|
+
[
|
|
1643
|
+
(1, "Alice", 20),
|
|
1644
|
+
(2, "Bob", 21),
|
|
1645
|
+
(3, "Charlie", 22),
|
|
1646
|
+
]
|
|
1647
|
+
)
|
|
1648
|
+
|
|
1649
|
+
mg.show(locals())
|
|
1650
|
+
conn.close()
|
|
1651
|
+
```
|
|
1652
|
+

|
|
1653
|
+
|
|
1654
|
+
|
|
1601
1655
|
# Memory Graph Web Debugger #
|
|
1602
1656
|
The <a href="https://memory-graph.com/#play" target="_blank">Memory Graph Web Debugger</a> lets us use memory_graph without any installation.
|
|
1603
1657
|

|
|
@@ -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.92"
|
|
6
6
|
__author__ = 'Bas Terwijn'
|
|
7
7
|
|
|
8
8
|
import memory_graph.memory_to_nodes as memory_to_nodes
|
|
@@ -520,6 +520,13 @@ def extend_pandas(on=True):
|
|
|
520
520
|
else:
|
|
521
521
|
ext_pd.unextend_pandas()
|
|
522
522
|
|
|
523
|
+
def extend_polars(on=True):
|
|
524
|
+
import memory_graph.extension_polars as ext_pl
|
|
525
|
+
if on:
|
|
526
|
+
ext_pl.extend_polars()
|
|
527
|
+
else:
|
|
528
|
+
ext_pl.unextend_polars()
|
|
529
|
+
|
|
523
530
|
def extend_torch(on=True):
|
|
524
531
|
import memory_graph.extension_torch as ext_torch
|
|
525
532
|
if on:
|
|
@@ -527,6 +534,12 @@ def extend_torch(on=True):
|
|
|
527
534
|
else:
|
|
528
535
|
ext_torch.unextend_torch()
|
|
529
536
|
|
|
537
|
+
def extend_sqlite3(on=True):
|
|
538
|
+
import memory_graph.extension_sqlite3 as ext_sqlite3
|
|
539
|
+
if on:
|
|
540
|
+
ext_sqlite3.extend_sqlite3()
|
|
541
|
+
else:
|
|
542
|
+
ext_sqlite3.unextend_sqlite3()
|
|
530
543
|
|
|
531
544
|
# ------------ collapse type
|
|
532
545
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# This file is part of memory_graph.
|
|
2
|
+
# Copyright (c) 2023, Bas Terwijn.
|
|
3
|
+
# SPDX-License-Identifier: BSD-2-Clause
|
|
4
|
+
|
|
5
|
+
""" Extension to add the memory graph configuration for Polars types. """
|
|
6
|
+
from memory_graph.node_table import Node_Table
|
|
7
|
+
|
|
8
|
+
import memory_graph.config as config
|
|
9
|
+
import memory_graph.config_default as config_default
|
|
10
|
+
|
|
11
|
+
def extend_polars():
|
|
12
|
+
import polars as pl
|
|
13
|
+
|
|
14
|
+
#config.type_to_color[pl.DataFrame] = "aquamarine"
|
|
15
|
+
config.type_to_node[pl.DataFrame] = lambda df: Node_Table(df,
|
|
16
|
+
df.iter_rows(),
|
|
17
|
+
col_names = df.columns)
|
|
18
|
+
config_default.type_to_color_light[pl.DataFrame] = "aquamarine"
|
|
19
|
+
config_default.type_to_color_dark[pl.DataFrame] = "#295345"
|
|
20
|
+
|
|
21
|
+
if not config.color_mode_dark:
|
|
22
|
+
config.type_to_color[pl.DataFrame] = config_default.type_to_color_light[pl.DataFrame]
|
|
23
|
+
else:
|
|
24
|
+
config.type_to_color[pl.DataFrame] = config_default.type_to_color_dark[pl.DataFrame]
|
|
25
|
+
|
|
26
|
+
def unextend_polars():
|
|
27
|
+
import polars as pl
|
|
28
|
+
|
|
29
|
+
del config.type_to_node[pl.DataFrame]
|
|
30
|
+
del config.type_to_color[pl.DataFrame]
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# This file is part of memory_graph.
|
|
2
|
+
# Copyright (c) 2023, Bas Terwijn.
|
|
3
|
+
# SPDX-License-Identifier: BSD-2-Clause
|
|
4
|
+
|
|
5
|
+
""" Extension to add the memory graph configuration for SQLite3 types. """
|
|
6
|
+
from memory_graph.node_key_value import Node_Key_Value
|
|
7
|
+
from memory_graph.node_table import Node_Table
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
import memory_graph.config as config
|
|
11
|
+
import memory_graph.config_default as config_default
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SQLite3_Table:
|
|
15
|
+
def __init__(self, header, rows, column_types, primary_keys, foreign_keys):
|
|
16
|
+
self.header = header
|
|
17
|
+
self.rows = rows
|
|
18
|
+
self.column_types = column_types
|
|
19
|
+
self.primary_keys = primary_keys
|
|
20
|
+
self.foreign_keys = foreign_keys
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_table(conn, table_name):
|
|
24
|
+
# Quote the table name safely
|
|
25
|
+
name = '"' + table_name.replace('"', '""') + '"'
|
|
26
|
+
|
|
27
|
+
cursor = conn.execute(f"SELECT * FROM {name}")
|
|
28
|
+
header = [col[0] for col in cursor.description]
|
|
29
|
+
rows = iter(cursor) # lazy iteration
|
|
30
|
+
# Column types: column name -> declared SQLite type
|
|
31
|
+
# Primary keys: column name -> position in composite primary key
|
|
32
|
+
column_info = list(conn.execute(f"PRAGMA table_info({name})"))
|
|
33
|
+
column_types = {
|
|
34
|
+
col[1]: col[2]
|
|
35
|
+
for col in column_info
|
|
36
|
+
}
|
|
37
|
+
primary_keys = {
|
|
38
|
+
col[1]: col[5]
|
|
39
|
+
for col in column_info
|
|
40
|
+
if col[5] > 0
|
|
41
|
+
}
|
|
42
|
+
# Foreign keys: (column, referenced table, referenced column)
|
|
43
|
+
foreign_keys = [
|
|
44
|
+
(fk[3], fk[2], fk[4])
|
|
45
|
+
for fk in conn.execute(f"PRAGMA foreign_key_list({name})")
|
|
46
|
+
]
|
|
47
|
+
return SQLite3_Table(
|
|
48
|
+
header, rows, column_types, primary_keys, foreign_keys
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def get_tables(conn):
|
|
53
|
+
import sqlite3
|
|
54
|
+
try:
|
|
55
|
+
table_names = (
|
|
56
|
+
row[0] for row in conn.execute(
|
|
57
|
+
"SELECT name FROM sqlite_master "
|
|
58
|
+
"WHERE type = 'table' AND name NOT LIKE 'sqlite_%'"
|
|
59
|
+
)
|
|
60
|
+
)
|
|
61
|
+
tables = {name: get_table(conn, name) for name in table_names}
|
|
62
|
+
return tables
|
|
63
|
+
except sqlite3.Error as e:
|
|
64
|
+
typename= type(e).__name__
|
|
65
|
+
error_msg = str(e)
|
|
66
|
+
tables = {typename: error_msg}
|
|
67
|
+
return tables
|
|
68
|
+
|
|
69
|
+
def sqlite_table_node(d):
|
|
70
|
+
import sqlite3
|
|
71
|
+
try:
|
|
72
|
+
headers = []
|
|
73
|
+
for name in d.header:
|
|
74
|
+
labels = []
|
|
75
|
+
# Declared SQLite column type
|
|
76
|
+
column_type = d.column_types.get(name)
|
|
77
|
+
if column_type:
|
|
78
|
+
labels.append(column_type)
|
|
79
|
+
# Primary key
|
|
80
|
+
if name in d.primary_keys:
|
|
81
|
+
labels.append("PK")
|
|
82
|
+
# Foreign key
|
|
83
|
+
if any(fk[0] == name for fk in d.foreign_keys):
|
|
84
|
+
labels.append("FK")
|
|
85
|
+
|
|
86
|
+
suffix = f" ({', '.join(labels)})" if labels else ""
|
|
87
|
+
headers.append(name + suffix)
|
|
88
|
+
return Node_Table(
|
|
89
|
+
d,
|
|
90
|
+
list(d.rows),
|
|
91
|
+
col_names=headers
|
|
92
|
+
)
|
|
93
|
+
except sqlite3.Error as e:
|
|
94
|
+
typename= type(e).__name__
|
|
95
|
+
error_msg = str(e)
|
|
96
|
+
return Node_Table(
|
|
97
|
+
d,
|
|
98
|
+
[[typename, error_msg]],
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
def extend_sqlite3():
|
|
102
|
+
import sqlite3
|
|
103
|
+
|
|
104
|
+
config.type_to_node[sqlite3.Connection] = (
|
|
105
|
+
lambda d: Node_Key_Value(d, get_tables(d).items())
|
|
106
|
+
)
|
|
107
|
+
config.type_to_node[SQLite3_Table] = sqlite_table_node
|
|
108
|
+
|
|
109
|
+
config_default.type_to_color_light[SQLite3_Table] = "lightcyan"
|
|
110
|
+
config_default.type_to_color_dark[SQLite3_Table] = "#2c4f52"
|
|
111
|
+
|
|
112
|
+
if not config.color_mode_dark:
|
|
113
|
+
config.type_to_color[SQLite3_Table] = config_default.type_to_color_light[SQLite3_Table]
|
|
114
|
+
else:
|
|
115
|
+
config.type_to_color[SQLite3_Table] = config_default.type_to_color_dark[SQLite3_Table]
|
|
116
|
+
|
|
117
|
+
def unextend_sqlite3():
|
|
118
|
+
del config.type_to_node[SQLite3_Table]
|
|
119
|
+
del config.type_to_color[SQLite3_Table]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: memory_graph
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.92
|
|
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
|
|
@@ -1556,8 +1556,8 @@ mg.show(locals())
|
|
|
1556
1556
|
# Extensions #
|
|
1557
1557
|
Different extensions are available for types from other Python packages.
|
|
1558
1558
|
|
|
1559
|
-
##
|
|
1560
|
-
For
|
|
1559
|
+
## NumPy ##
|
|
1560
|
+
For NumPy types `array` and `matrix` and `ndarray`, use `mg.extend_numpy()`:
|
|
1561
1561
|
|
|
1562
1562
|
```python
|
|
1563
1563
|
import memory_graph as mg
|
|
@@ -1574,12 +1574,12 @@ mg.show(locals())
|
|
|
1574
1574
|
```
|
|
1575
1575
|

|
|
1576
1576
|
|
|
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).
|
|
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×tep=0.5&play).
|
|
1578
1578
|
|
|
1579
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×tep=0.5&play).
|
|
1580
1580
|
|
|
1581
1581
|
## Pandas ##
|
|
1582
|
-
For
|
|
1582
|
+
For Pandas types `Series` and `DataFrame`, use `mg.extend_pandas()`:
|
|
1583
1583
|
|
|
1584
1584
|
```python
|
|
1585
1585
|
import memory_graph as mg
|
|
@@ -1597,9 +1597,30 @@ mg.show(locals())
|
|
|
1597
1597
|
```
|
|
1598
1598
|

|
|
1599
1599
|
|
|
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).
|
|
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×tep=0.5&play).
|
|
1601
|
+
|
|
1602
|
+
See this [introduction to Pandas operations](https://memory-graph.com/#micropip=numpy,pandas&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/pandas_operations.py×tep=0.5&play).
|
|
1603
|
+
|
|
1604
|
+
## Polars ##
|
|
1605
|
+
For Polars types `DataFrame`, use `mg.extend_polars()`:
|
|
1606
|
+
|
|
1607
|
+
```python
|
|
1608
|
+
import memory_graph as mg
|
|
1609
|
+
import polars as pl
|
|
1610
|
+
mg.extend_polars()
|
|
1611
|
+
|
|
1612
|
+
df = pl.DataFrame(
|
|
1613
|
+
{
|
|
1614
|
+
"name": ["Alice Archer", "Ben Brown", "Chloe Cooper", "Daniel Donovan"],
|
|
1615
|
+
"weight": [57.9, 72.5, 53.6, 83.1], # (kg)
|
|
1616
|
+
"height": [1.56, 1.77, 1.65, 1.75], # (m)
|
|
1617
|
+
}
|
|
1618
|
+
)
|
|
1619
|
+
|
|
1620
|
+
mg.show(locals())
|
|
1621
|
+
```
|
|
1622
|
+

|
|
1601
1623
|
|
|
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×tep=0.5&play).
|
|
1603
1624
|
|
|
1604
1625
|
## PyTorch ##
|
|
1605
1626
|
For torch type `tensor`, use `mg.extend_torch()`:
|
|
@@ -1618,6 +1639,39 @@ mg.show(locals())
|
|
|
1618
1639
|
```
|
|
1619
1640
|

|
|
1620
1641
|
|
|
1642
|
+
## SQLite3 ##
|
|
1643
|
+
For sqlite3 use `mg.extend_sqlite3()`:
|
|
1644
|
+
|
|
1645
|
+
```python
|
|
1646
|
+
import memory_graph as mg
|
|
1647
|
+
import sqlite3
|
|
1648
|
+
mg.extend_sqlite3()
|
|
1649
|
+
|
|
1650
|
+
conn = sqlite3.connect(":memory:")
|
|
1651
|
+
|
|
1652
|
+
conn.executescript("""
|
|
1653
|
+
CREATE TABLE students (
|
|
1654
|
+
id INTEGER PRIMARY KEY,
|
|
1655
|
+
name TEXT NOT NULL,
|
|
1656
|
+
age INTEGER
|
|
1657
|
+
);
|
|
1658
|
+
""")
|
|
1659
|
+
|
|
1660
|
+
conn.executemany(
|
|
1661
|
+
"INSERT INTO students VALUES (?, ?, ?)",
|
|
1662
|
+
[
|
|
1663
|
+
(1, "Alice", 20),
|
|
1664
|
+
(2, "Bob", 21),
|
|
1665
|
+
(3, "Charlie", 22),
|
|
1666
|
+
]
|
|
1667
|
+
)
|
|
1668
|
+
|
|
1669
|
+
mg.show(locals())
|
|
1670
|
+
conn.close()
|
|
1671
|
+
```
|
|
1672
|
+

|
|
1673
|
+
|
|
1674
|
+
|
|
1621
1675
|
# Memory Graph Web Debugger #
|
|
1622
1676
|
The <a href="https://memory-graph.com/#play" target="_blank">Memory Graph Web Debugger</a> lets us use memory_graph without any installation.
|
|
1623
1677
|

|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
LICENSE.txt
|
|
2
2
|
README.md
|
|
3
3
|
pyproject.toml
|
|
4
|
-
setup.py
|
|
5
4
|
memory_graph/__init__.py
|
|
6
5
|
memory_graph/call_stack.py
|
|
7
6
|
memory_graph/config.py
|
|
@@ -9,6 +8,8 @@ memory_graph/config_default.py
|
|
|
9
8
|
memory_graph/config_helpers.py
|
|
10
9
|
memory_graph/extension_numpy.py
|
|
11
10
|
memory_graph/extension_pandas.py
|
|
11
|
+
memory_graph/extension_polars.py
|
|
12
|
+
memory_graph/extension_sqlite3.py
|
|
12
13
|
memory_graph/extension_torch.py
|
|
13
14
|
memory_graph/html_table.py
|
|
14
15
|
memory_graph/list_view.py
|
|
@@ -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.92"
|
|
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"}
|
memory_graph-0.3.90/setup.py
DELETED
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|