forked from ibis-project/ibis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_matrix.py
78 lines (59 loc) · 1.83 KB
/
gen_matrix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from pathlib import Path
import pandas as pd
import tomli
import ibis
import ibis.expr.operations as ops
def get_backends():
pyproject = tomli.loads(Path("pyproject.toml").read_text())
backends = pyproject["tool"]["poetry"]["plugins"]["ibis.backends"]
del backends["spark"]
return [
(backend, getattr(ibis, backend))
for backend in sorted(backends.keys())
]
def get_leaf_classes(op):
for child_class in op.__subclasses__():
if not child_class.__subclasses__():
yield child_class
else:
yield from get_leaf_classes(child_class)
EXCLUDED_OPS = {
# Never translates into anything
ops.UnresolvedExistsSubquery,
ops.UnresolvedNotExistsSubquery,
ops.ScalarParameter,
}
INCLUDED_OPS = {
# Parent class of MultiQuantile so it's ignored by `get_backends()`
ops.Quantile,
}
ICONS = {
True: ":material-check-decagram:{ .verified }",
False: ":material-cancel:{ .cancel }",
}
def main():
possible_ops = (
frozenset(get_leaf_classes(ops.Value)) | INCLUDED_OPS
) - EXCLUDED_OPS
support = {"operation": [f"`{op.__name__}`" for op in possible_ops]}
support.update(
(name, list(map(backend.has_operation, possible_ops)))
for name, backend in get_backends()
)
df = pd.DataFrame(support).set_index("operation").sort_index()
counts = df.sum().sort_values(ascending=False)
num_ops = len(possible_ops)
coverage = (
counts.map(lambda n: f"_{n} ({round(100 * n / num_ops)}%)_")
.to_frame(name="**API Coverage**")
.T
)
ops_table = df.loc[:, counts.index].replace(ICONS)
table = pd.concat([coverage, ops_table])
dst = Path(__file__).parent.joinpath(
"docs",
"backends",
"support_matrix.csv",
)
table.to_csv(dst, index_label="Backends")
main()