Skip to content

Commit 1fd8bc5

Browse files
committed
Add Jupyter notebook tests and run it in CI
1 parent fdc418f commit 1fd8bc5

File tree

5 files changed

+118
-4
lines changed

5 files changed

+118
-4
lines changed

.github/workflows/build_linux_arm64_wheels-gh.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
echo "Installing dependencies for Python $version"
7373
pyenv shell $version
7474
python -m pip install --upgrade pip
75-
python -m pip install setuptools tox pandas pyarrow twine psutil deltalake wheel
75+
python -m pip install setuptools tox pandas pyarrow twine psutil deltalake wheel jupyter nbconvert
7676
pyenv shell --unset
7777
done
7878
- name: Install clang++ for Ubuntu
@@ -187,6 +187,15 @@ jobs:
187187
pyenv shell --unset
188188
done
189189
continue-on-error: false
190+
- name: Run notebook tests
191+
run: |
192+
export PATH="$HOME/.pyenv/bin:$PATH"
193+
eval "$(pyenv init -)"
194+
pyenv shell 3.8
195+
python -m pip install dist/*.whl --force-reinstall
196+
jupyter nbconvert --to notebook --execute tests/test_data_insertion.ipynb --output test_data_insertion_output.ipynb
197+
pyenv shell --unset
198+
continue-on-error: false
190199
- name: Check and upload core files if present
191200
if: always()
192201
run: |

.github/workflows/build_linux_x86_wheels.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
echo "Installing dependencies for Python $version"
7373
pyenv shell $version
7474
python -m pip install --upgrade pip
75-
python -m pip install setuptools tox pandas pyarrow twine psutil deltalake wheel
75+
python -m pip install setuptools tox pandas pyarrow twine psutil deltalake wheel jupyter nbconvert
7676
pyenv shell --unset
7777
done
7878
- name: Install clang++ for Ubuntu
@@ -186,6 +186,15 @@ jobs:
186186
pyenv shell --unset
187187
done
188188
continue-on-error: false
189+
- name: Run notebook tests
190+
run: |
191+
export PATH="$HOME/.pyenv/bin:$PATH"
192+
eval "$(pyenv init -)"
193+
pyenv shell 3.8
194+
python -m pip install dist/*.whl --force-reinstall
195+
jupyter nbconvert --to notebook --execute tests/test_data_insertion.ipynb --output test_data_insertion_output.ipynb
196+
pyenv shell --unset
197+
continue-on-error: false
189198
- name: Check and upload core files if present
190199
if: always()
191200
run: |

.github/workflows/build_macos_arm64_wheels.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
echo "Installing dependencies for Python $version"
6565
pyenv shell $version
6666
python -m pip install --upgrade pip
67-
python -m pip install setuptools wheel tox pandas pyarrow twine psutil deltalake wheel>=0.40.0
67+
python -m pip install setuptools wheel tox pandas pyarrow twine psutil deltalake wheel>=0.40.0 jupyter nbconvert
6868
pyenv shell --unset
6969
done
7070
- name: Remove /usr/local/bin/python3
@@ -190,6 +190,15 @@ jobs:
190190
pyenv shell --unset
191191
done
192192
continue-on-error: false
193+
- name: Run notebook tests
194+
run: |
195+
export PATH="$HOME/.pyenv/bin:$PATH"
196+
eval "$(pyenv init -)"
197+
pyenv shell 3.8
198+
python -m pip install dist/*.whl --force-reinstall
199+
jupyter nbconvert --to notebook --execute tests/test_data_insertion.ipynb --output test_data_insertion_output.ipynb
200+
pyenv shell --unset
201+
continue-on-error: false
193202
- name: Check and upload core files if present
194203
if: always()
195204
run: |

.github/workflows/build_macos_x86_wheels.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
echo "Installing dependencies for Python $version"
6565
pyenv shell $version
6666
python -m pip install --upgrade pip
67-
python -m pip install setuptools tox pandas pyarrow twine psutil deltalake wheel>=0.40.0
67+
python -m pip install setuptools tox pandas pyarrow twine psutil deltalake wheel>=0.40.0 jupyter nbconvert
6868
pyenv shell --unset
6969
done
7070
- name: Remove /usr/local/bin/python3
@@ -191,6 +191,15 @@ jobs:
191191
pyenv shell --unset
192192
done
193193
continue-on-error: false
194+
- name: Run notebook tests
195+
run: |
196+
export PATH="$HOME/.pyenv/bin:$PATH"
197+
eval "$(pyenv init -)"
198+
pyenv shell 3.8
199+
python -m pip install dist/*.whl --force-reinstall
200+
jupyter nbconvert --to notebook --execute tests/test_data_insertion.ipynb --output test_data_insertion_output.ipynb
201+
pyenv shell --unset
202+
continue-on-error: false
194203
- name: Check and upload core files if present
195204
if: always()
196205
run: |

tests/test_data_insertion.ipynb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"metadata": {
6+
"ExecuteTime": {
7+
"end_time": "2025-09-17T06:03:01.458132Z",
8+
"start_time": "2025-09-17T06:03:00.939968Z"
9+
}
10+
},
11+
"source": [
12+
"print(\"start\")\n",
13+
"from chdb import session\n",
14+
"print(\"Connecting to database\")\n",
15+
"chs = session.Session()\n",
16+
"print(\"Creating database\")\n",
17+
"chs.query(\"CREATE DATABASE IF NOT EXISTS movie_embeddings ENGINE = Atomic\")\n",
18+
"print(\"Creating table\")\n",
19+
"chs.query(\"USE movie_embeddings\")\n",
20+
"chs.query('DROP TABLE IF EXISTS embeddings')\n",
21+
"chs.query('DROP TABLE IF EXISTS embeddings_with_title')\n",
22+
"\n",
23+
"print(\"Creating table with movie titles\")\n",
24+
"\n",
25+
"chs.query(\"\"\"CREATE TABLE embeddings (\n",
26+
" movieId UInt32 NOT NULL,\n",
27+
" embedding Array(Float32) NOT NULL\n",
28+
" ) ENGINE = MergeTree()\n",
29+
" ORDER BY movieId\"\"\")\n",
30+
"\n",
31+
"print(\"Inserting movie embeddings into the database\")\n",
32+
"\n",
33+
"# Insert from INFILE and VALUES got stuck either\n",
34+
"# chs.query(\"INSERT INTO embeddings FROM INFILE 'movie_embeddings.csv' FORMAT CSV\")\n",
35+
"chs.query(\"INSERT INTO embeddings VALUES (1, [1,2,3,4,5,6,7,8,9,10])\")\n",
36+
"print(chs.query('SELECT * FROM embeddings LIMIT 5'))"
37+
],
38+
"outputs": [
39+
{
40+
"name": "stdout",
41+
"output_type": "stream",
42+
"text": [
43+
"start\n",
44+
"Connecting to database\n",
45+
"Creating database\n",
46+
"Creating table\n",
47+
"Creating table with movie titles\n",
48+
"Inserting movie embeddings into the database\n",
49+
"1,\"[1,2,3,4,5,6,7,8,9,10]\"\n",
50+
"\n"
51+
]
52+
}
53+
],
54+
"execution_count": 1
55+
}
56+
],
57+
"metadata": {
58+
"kernelspec": {
59+
"display_name": "Python 3",
60+
"language": "python",
61+
"name": "python3"
62+
},
63+
"language_info": {
64+
"codemirror_mode": {
65+
"name": "ipython",
66+
"version": 3
67+
},
68+
"file_extension": ".py",
69+
"mimetype": "text/x-python",
70+
"name": "python",
71+
"nbconvert_exporter": "python",
72+
"pygments_lexer": "ipython3",
73+
"version": "3.8.0"
74+
}
75+
},
76+
"nbformat": 4,
77+
"nbformat_minor": 4
78+
}

0 commit comments

Comments
 (0)