Skip to content

Commit a7e099d

Browse files
committed
add call interface, rebuild and retest
1 parent 5114ce1 commit a7e099d

File tree

14 files changed

+2035
-1621
lines changed

14 files changed

+2035
-1621
lines changed

Examples/cdata/pivot_unpivot.ipynb

Lines changed: 444 additions & 74 deletions
Large diffs are not rendered by default.

build/lib/data_algebra/data_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2837,7 +2837,7 @@ def to_near_sql_implementation_(
28372837
view_name = "convert_records_blocks_out_" + str(temp_id_source[0])
28382838
temp_id_source[0] = temp_id_source[0] + 1
28392839
pi, si = db_model.row_recs_to_blocks_query_str_list_pair(
2840-
record_spec=self.record_map.blocks_out,
2840+
record_spec=self.record_map.blocks_out
28412841
)
28422842
near_sql = data_algebra.near_sql.NearSQLRawQStep(
28432843
prefix=pi,

build/lib/data_algebra/db_model.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,9 +1931,12 @@ def row_recs_to_blocks_query_str_list_pair(
19311931
"""
19321932
Convert row recs to blocks transformation into structures to help with SQL conversion.
19331933
"""
1934+
ct = record_spec.control_table
1935+
dm = data_algebra.data_model.lookup_data_model_for_dataframe(ct)
1936+
ct = dm.to_pandas(ct)
19341937
control_value_cols = [
19351938
c
1936-
for c in record_spec.control_table.columns
1939+
for c in ct.columns
19371940
if c not in record_spec.control_table_keys
19381941
]
19391942
control_cols = [
@@ -1960,7 +1963,7 @@ def row_recs_to_blocks_query_str_list_pair(
19601963
continue
19611964
seen.add(result_col)
19621965
cstmt = " CASE "
1963-
col = record_spec.control_table[result_col]
1966+
col = ct[result_col]
19641967
isnull = col.isnull()
19651968
for i in range(len(col)):
19661969
if not (isnull[i]):
@@ -1979,7 +1982,7 @@ def row_recs_to_blocks_query_str_list_pair(
19791982
cstmt = cstmt + col_sql
19801983
cstmt = cstmt + " ELSE NULL END AS " + self.quote_identifier(result_col)
19811984
col_stmts.append(cstmt)
1982-
ctab_sql = self.table_values_to_sql_str_list(record_spec.control_table)
1985+
ctab_sql = self.table_values_to_sql_str_list(ct)
19831986
sql_prefix = _list_join_expecting_list(",", col_stmts) + [
19841987
"FROM ( SELECT * FROM "
19851988
]
@@ -2000,17 +2003,20 @@ def blocks_to_row_recs_query_str_list_pair(
20002003
"""
20012004
Convert blocks to row recs transform into structures to help with SQL translation.
20022005
"""
2003-
assert record_spec.control_table.shape[0] >= 1
2006+
ct = record_spec.control_table
2007+
dm = data_algebra.data_model.lookup_data_model_for_dataframe(ct)
2008+
ct = dm.to_pandas(ct)
2009+
assert ct.shape[0] >= 1
20042010
col_stmts = []
20052011
for c in record_spec.record_keys:
20062012
col_stmts.append(
20072013
" " + self.quote_identifier(c) + " AS " + self.quote_identifier(c)
20082014
)
2009-
if record_spec.control_table.shape[0] == 1:
2015+
if ct.shape[0] == 1:
20102016
# special case with one row control table (rowrec)
2011-
for cc in record_spec.control_table.columns:
2017+
for cc in ct.columns:
20122018
if cc not in record_spec.control_table_keys:
2013-
cc0 = record_spec.control_table[cc][0]
2019+
cc0 = ct[cc][0]
20142020
col_stmts.append(
20152021
" "
20162022
+ self.quote_identifier(cc)
@@ -2024,14 +2030,14 @@ def blocks_to_row_recs_query_str_list_pair(
20242030
return sql_prefix, sql_suffix
20252031
control_value_cols = [
20262032
c
2027-
for c in record_spec.control_table.columns
2033+
for c in ct.columns
20282034
if c not in record_spec.control_table_keys
20292035
]
20302036
control_cols = [self.quote_identifier(c) for c in record_spec.record_keys]
20312037
seen = set()
2032-
for i in range(record_spec.control_table.shape[0]):
2038+
for i in range(ct.shape[0]):
20332039
for vc in control_value_cols:
2034-
col = record_spec.control_table[vc]
2040+
col = ct[vc]
20352041
isnull = col.isnull()
20362042
if col[i] not in seen and not isnull[i]:
20372043
seen.add(col[i])
@@ -2043,7 +2049,7 @@ def blocks_to_row_recs_query_str_list_pair(
20432049
+ " AS "
20442050
+ self.string_type
20452051
+ ") = "
2046-
+ self.quote_string(str(record_spec.control_table[cc][i]))
2052+
+ self.quote_string(str(ct[cc][i]))
20472053
+ " ) "
20482054
)
20492055
cstmt = (

build/lib/data_algebra/shift_pipe_action.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ def __rrshift__(self, b): # override b >> self
3636
This is read as sending b to self.
3737
"""
3838
return self.act_on(b, correct_ordered_first_call=True)
39+
40+
def __call__(self, b):
41+
return self.act_on(b, correct_ordered_first_call=True)

coverage.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ data_algebra/data_ops.py 1322 205 84% 36-37, 56-57, 94, 1
149149
data_algebra/data_ops_types.py 67 1 99% 312
150150
data_algebra/data_ops_utils.py 33 3 91% 29, 33, 43
151151
data_algebra/data_space.py 25 1 96% 76
152-
data_algebra/db_model.py 999 97 90% 43, 58, 66-68, 204, 339-340, 420, 844, 856, 914, 921, 929-930, 949-953, 963, 977-981, 1005, 1017, 1076, 1078, 1084, 1095, 1107, 1139, 1143, 1148, 1181, 1185, 1201, 1204, 1284, 1295, 1300, 1323, 1327, 1368, 1375, 1413, 1417, 1435, 1450, 1454, 1476, 1480, 1494, 1534, 1538, 1574, 1578, 1639, 1643, 1645, 1648, 1673, 1752, 1756, 1760, 1763, 1768, 1811, 1822, 1960, 2011-2024, 2078-2079, 2097, 2106, 2121, 2127, 2129, 2133, 2142, 2157, 2166, 2207, 2244, 2247, 2254, 2362, 2455-2458, 2463-2464, 2468
152+
data_algebra/db_model.py 1005 97 90% 43, 58, 66-68, 204, 339-340, 420, 844, 856, 914, 921, 929-930, 949-953, 963, 977-981, 1005, 1017, 1076, 1078, 1084, 1095, 1107, 1139, 1143, 1148, 1181, 1185, 1201, 1204, 1284, 1295, 1300, 1323, 1327, 1368, 1375, 1413, 1417, 1435, 1450, 1454, 1476, 1480, 1494, 1534, 1538, 1574, 1578, 1639, 1643, 1645, 1648, 1673, 1752, 1756, 1760, 1763, 1768, 1811, 1822, 1963, 2017-2030, 2084-2085, 2103, 2112, 2127, 2133, 2135, 2139, 2148, 2163, 2172, 2213, 2250, 2253, 2260, 2368, 2461-2464, 2469-2470, 2474
153153
data_algebra/db_space.py 76 16 79% 58-59, 63, 73-77, 83, 118-119, 132-133, 137-139
154154
data_algebra/eval_cache.py 51 0 100%
155155
data_algebra/expr_parse.py 34 0 100%
@@ -163,13 +163,13 @@ data_algebra/pandas_model.py 19 2 89% 32-33
163163
data_algebra/parse_by_lark.py 164 24 85% 71, 93, 108, 129-130, 137, 161, 171, 185-186, 188, 200, 206, 213-217, 245, 253, 263-266
164164
data_algebra/polars_model.py 597 74 88% 180, 189, 203, 446-452, 458-465, 483-484, 486, 570, 586, 596, 603, 616-620, 628, 630, 655, 658, 663, 666, 715, 733, 749, 816, 832-834, 879, 922, 941, 950, 965, 983, 1001, 1021, 1033-1035, 1038, 1045, 1047, 1054-1066, 1073, 1078, 1109, 1138, 1147, 1175, 1190, 1202
165165
data_algebra/python3_lark.py 1 0 100%
166-
data_algebra/shift_pipe_action.py 12 0 100%
166+
data_algebra/shift_pipe_action.py 14 0 100%
167167
data_algebra/solutions.py 135 4 97% 63, 308, 389, 472
168168
data_algebra/sql_format_options.py 17 4 76% 61, 68-71
169169
data_algebra/test_util.py 334 59 82% 28-29, 104, 126, 136, 139, 143, 166, 169, 173, 175-178, 189, 264-269, 273, 285, 295, 332, 334, 345, 353, 364, 371, 377, 389, 400, 414, 469, 473, 524-527, 529-532, 534-537, 539-542, 653-658, 663-664, 666
170170
data_algebra/util.py 127 28 78% 26, 59-60, 63-64, 67-68, 71-72, 75-76, 79-80, 83-84, 87-88, 91-92, 95-96, 143, 165, 167, 182, 223, 227, 229
171171
--------------------------------------------------------------------
172-
TOTAL 6697 908 86%
172+
TOTAL 6705 908 86%
173173

174174

175-
======================= 373 passed in 842.88s (0:14:02) ========================
175+
======================= 373 passed in 825.96s (0:13:45) ========================

data_algebra/data_ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2837,7 +2837,7 @@ def to_near_sql_implementation_(
28372837
view_name = "convert_records_blocks_out_" + str(temp_id_source[0])
28382838
temp_id_source[0] = temp_id_source[0] + 1
28392839
pi, si = db_model.row_recs_to_blocks_query_str_list_pair(
2840-
record_spec=self.record_map.blocks_out,
2840+
record_spec=self.record_map.blocks_out
28412841
)
28422842
near_sql = data_algebra.near_sql.NearSQLRawQStep(
28432843
prefix=pi,

data_algebra/db_model.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,9 +1931,12 @@ def row_recs_to_blocks_query_str_list_pair(
19311931
"""
19321932
Convert row recs to blocks transformation into structures to help with SQL conversion.
19331933
"""
1934+
ct = record_spec.control_table
1935+
dm = data_algebra.data_model.lookup_data_model_for_dataframe(ct)
1936+
ct = dm.to_pandas(ct)
19341937
control_value_cols = [
19351938
c
1936-
for c in record_spec.control_table.columns
1939+
for c in ct.columns
19371940
if c not in record_spec.control_table_keys
19381941
]
19391942
control_cols = [
@@ -1960,7 +1963,7 @@ def row_recs_to_blocks_query_str_list_pair(
19601963
continue
19611964
seen.add(result_col)
19621965
cstmt = " CASE "
1963-
col = record_spec.control_table[result_col]
1966+
col = ct[result_col]
19641967
isnull = col.isnull()
19651968
for i in range(len(col)):
19661969
if not (isnull[i]):
@@ -1979,7 +1982,7 @@ def row_recs_to_blocks_query_str_list_pair(
19791982
cstmt = cstmt + col_sql
19801983
cstmt = cstmt + " ELSE NULL END AS " + self.quote_identifier(result_col)
19811984
col_stmts.append(cstmt)
1982-
ctab_sql = self.table_values_to_sql_str_list(record_spec.control_table)
1985+
ctab_sql = self.table_values_to_sql_str_list(ct)
19831986
sql_prefix = _list_join_expecting_list(",", col_stmts) + [
19841987
"FROM ( SELECT * FROM "
19851988
]
@@ -2000,17 +2003,20 @@ def blocks_to_row_recs_query_str_list_pair(
20002003
"""
20012004
Convert blocks to row recs transform into structures to help with SQL translation.
20022005
"""
2003-
assert record_spec.control_table.shape[0] >= 1
2006+
ct = record_spec.control_table
2007+
dm = data_algebra.data_model.lookup_data_model_for_dataframe(ct)
2008+
ct = dm.to_pandas(ct)
2009+
assert ct.shape[0] >= 1
20042010
col_stmts = []
20052011
for c in record_spec.record_keys:
20062012
col_stmts.append(
20072013
" " + self.quote_identifier(c) + " AS " + self.quote_identifier(c)
20082014
)
2009-
if record_spec.control_table.shape[0] == 1:
2015+
if ct.shape[0] == 1:
20102016
# special case with one row control table (rowrec)
2011-
for cc in record_spec.control_table.columns:
2017+
for cc in ct.columns:
20122018
if cc not in record_spec.control_table_keys:
2013-
cc0 = record_spec.control_table[cc][0]
2019+
cc0 = ct[cc][0]
20142020
col_stmts.append(
20152021
" "
20162022
+ self.quote_identifier(cc)
@@ -2024,14 +2030,14 @@ def blocks_to_row_recs_query_str_list_pair(
20242030
return sql_prefix, sql_suffix
20252031
control_value_cols = [
20262032
c
2027-
for c in record_spec.control_table.columns
2033+
for c in ct.columns
20282034
if c not in record_spec.control_table_keys
20292035
]
20302036
control_cols = [self.quote_identifier(c) for c in record_spec.record_keys]
20312037
seen = set()
2032-
for i in range(record_spec.control_table.shape[0]):
2038+
for i in range(ct.shape[0]):
20332039
for vc in control_value_cols:
2034-
col = record_spec.control_table[vc]
2040+
col = ct[vc]
20352041
isnull = col.isnull()
20362042
if col[i] not in seen and not isnull[i]:
20372043
seen.add(col[i])
@@ -2043,7 +2049,7 @@ def blocks_to_row_recs_query_str_list_pair(
20432049
+ " AS "
20442050
+ self.string_type
20452051
+ ") = "
2046-
+ self.quote_string(str(record_spec.control_table[cc][i]))
2052+
+ self.quote_string(str(ct[cc][i]))
20472053
+ " ) "
20482054
)
20492055
cstmt = (

data_algebra/shift_pipe_action.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ def __rrshift__(self, b): # override b >> self
3636
This is read as sending b to self.
3737
"""
3838
return self.act_on(b, correct_ordered_first_call=True)
39+
40+
def __call__(self, b):
41+
return self.act_on(b, correct_ordered_first_call=True)
28 Bytes
Binary file not shown.

dist/data_algebra-1.6.4.tar.gz

17 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)