Skip to content

Commit 23b322a

Browse files
committed
work on example
1 parent b0e8050 commit 23b322a

File tree

5 files changed

+112
-10
lines changed

5 files changed

+112
-10
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"import pandas as pd\n",
12+
"from data_algebra.data_ops import data, descr, ex\n",
13+
"from data_algebra.BigQuery import BigQueryModel, BigQuery_DBHandle\n",
14+
"\n",
15+
"\n",
16+
"d = pd.DataFrame({\n",
17+
" 'group': ['a', 'a', 'b', 'b', 'b'],\n",
18+
" 'one': [1, 1, 1, 1, 1],\n",
19+
"})\n",
20+
"\n",
21+
"ops = (\n",
22+
" descr(d=d)\n",
23+
" .project(\n",
24+
" {\n",
25+
" 'sum_one': 'one.sum()',\n",
26+
" 'sum_1': '(1).sum()',\n",
27+
" },\n",
28+
" group_by=['group']\n",
29+
" )\n",
30+
")\n",
31+
"\n",
32+
"ops.transform(d)"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": null,
38+
"outputs": [],
39+
"source": [
40+
"db_model = BigQueryModel()\n",
41+
"\n",
42+
"print(db_model.to_sql(ops))\n"
43+
],
44+
"metadata": {
45+
"collapsed": false,
46+
"pycharm": {
47+
"name": "#%%\n"
48+
}
49+
}
50+
}
51+
],
52+
"metadata": {
53+
"kernelspec": {
54+
"display_name": "Python 3",
55+
"language": "python",
56+
"name": "python3"
57+
},
58+
"language_info": {
59+
"codemirror_mode": {
60+
"name": "ipython",
61+
"version": 2
62+
},
63+
"file_extension": ".py",
64+
"mimetype": "text/x-python",
65+
"name": "python",
66+
"nbconvert_exporter": "python",
67+
"pygments_lexer": "ipython2",
68+
"version": "2.7.6"
69+
}
70+
},
71+
"nbformat": 4,
72+
"nbformat_minor": 0
73+
}

coverage.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
platform darwin -- Python 3.9.7, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
33
rootdir: /Users/johnmount/Documents/work/data_algebra
44
plugins: cov-2.12.1, anyio-2.2.0, typeguard-2.13.0
5-
collected 249 items
5+
collected 250 items
66

77
tests/test_OrderedSet.py .... [ 1%]
88
tests/test_agg.py . [ 2%]
@@ -60,41 +60,42 @@ tests/test_one_row_cdata_convert.py . [ 47%]
6060
tests/test_ops.py . [ 48%]
6161
tests/test_ops_eq.py . [ 48%]
6262
tests/test_or.py ..... [ 50%]
63-
tests/test_order_limit.py . [ 51%]
63+
tests/test_order_limit.py . [ 50%]
6464
tests/test_ordered_agg_group.py . [ 51%]
6565
tests/test_parse.py .......................... [ 61%]
6666
tests/test_project.py ..... [ 63%]
6767
tests/test_ranked_example.py . [ 64%]
6868
tests/test_readme_example.py . [ 64%]
6969
tests/test_ref_detect.py .. [ 65%]
7070
tests/test_rename.py . [ 65%]
71-
tests/test_round.py ... [ 67%]
71+
tests/test_round.py ... [ 66%]
7272
tests/test_scalar_columns.py . [ 67%]
7373
tests/test_scatter_example.py . [ 67%]
7474
tests/test_scoring_example.py . [ 68%]
7575
tests/test_select.py ... [ 69%]
7676
tests/test_select_stacking.py . [ 69%]
7777
tests/test_select_values.py .. [ 70%]
78-
tests/test_set_quoting.py ...... [ 73%]
78+
tests/test_set_quoting.py ...... [ 72%]
7979
tests/test_shorten.py . [ 73%]
8080
tests/test_sign_parse.py .. [ 74%]
8181
tests/test_simple.py .... [ 75%]
8282
tests/test_simple_expr.py . [ 76%]
83-
tests/test_simplification.py .. [ 77%]
83+
tests/test_simplification.py .. [ 76%]
8484
tests/test_spark_sql.py . [ 77%]
8585
tests/test_sql_extend_shortening.py .. [ 78%]
8686
tests/test_sqlite.py ............. [ 83%]
8787
tests/test_sqlite_joins.py ... [ 84%]
8888
tests/test_strat_example.py .. [ 85%]
8989
tests/test_sum_cumsum.py . [ 85%]
90+
tests/test_sum_one.py . [ 86%]
9091
tests/test_t_test_example.py . [ 86%]
9192
tests/test_table_is_key_by_columns.py . [ 86%]
9293
tests/test_table_q.py . [ 87%]
9394
tests/test_transform_examples.py ........... [ 91%]
94-
tests/test_types.py . [ 91%]
95+
tests/test_types.py . [ 92%]
9596
tests/test_uniform.py .. [ 92%]
9697
tests/test_use.py .. [ 93%]
97-
tests/test_user_sql.py . [ 93%]
98+
tests/test_user_sql.py . [ 94%]
9899
tests/test_value_behaves_like_column.py .... [ 95%]
99100
tests/test_window2.py ... [ 96%]
100101
tests/test_window_fns.py ..... [ 98%]
@@ -108,7 +109,7 @@ data_algebra/BigQuery.py 108 67 38%
108109
data_algebra/MySQL.py 28 10 64%
109110
data_algebra/OrderedSet.py 73 9 88%
110111
data_algebra/PostgreSQL.py 21 7 67%
111-
data_algebra/SQLite.py 151 20 87%
112+
data_algebra/SQLite.py 151 21 86%
112113
data_algebra/SparkSQL.py 81 45 44%
113114
data_algebra/__init__.py 5 0 100%
114115
data_algebra/arrow.py 141 32 77%
@@ -131,7 +132,7 @@ data_algebra/python3_lark.py 1 0 100%
131132
data_algebra/test_util.py 273 50 82%
132133
data_algebra/util.py 140 29 79%
133134
----------------------------------------------------------
134-
TOTAL 5263 908 83%
135+
TOTAL 5263 909 83%
135136

136137

137-
============================= 249 passed in 27.37s =============================
138+
============================= 250 passed in 27.40s =============================
0 Bytes
Binary file not shown.

dist/data_algebra-1.2.1.tar.gz

1 Byte
Binary file not shown.

tests/test_sum_one.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
import data_algebra
3+
import data_algebra.test_util
4+
from data_algebra.data_ops import data, descr, ex
5+
6+
7+
def test_sum_one():
8+
d = data_algebra.default_data_model.pd.DataFrame({
9+
'group': ['a', 'a', 'b', 'b', 'b'],
10+
'one': [1, 1, 1, 1, 1],
11+
})
12+
ops = (
13+
descr(d=d)
14+
.project(
15+
{
16+
'sum_one': 'one.sum()',
17+
'sum_1': '(1).sum()',
18+
},
19+
group_by=['group']
20+
)
21+
)
22+
expect = data_algebra.default_data_model.pd.DataFrame({
23+
'group': ['a', 'b'],
24+
'sum_one': [2, 3],
25+
'sum_1': [2, 3],
26+
})
27+
data_algebra.test_util.check_transform(ops=ops, data=d, expect=expect)
28+

0 commit comments

Comments
 (0)