Skip to content

Commit

Permalink
chore: move support matrix construction to debuggable script
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and gforsyth committed Feb 16, 2024
1 parent b2ae64a commit 61525e4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 56 deletions.
52 changes: 52 additions & 0 deletions docs/support_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from __future__ import annotations

import pandas as pd

import ibis
import ibis.expr.operations as ops


def make_support_matrix():
"""Construct the backend operation support matrix data."""

from ibis.backends.base.sqlglot.compiler import ALL_OPERATIONS

support_matrix_ignored_operations = (ops.ScalarParameter,)

public_ops = ALL_OPERATIONS.difference(support_matrix_ignored_operations)

assert public_ops

support = {"Operation": [f"{op.__module__}.{op.__name__}" for op in public_ops]}
support.update(
(backend, list(map(getattr(ibis, backend).has_operation, public_ops)))
for backend in sorted(ep.name for ep in ibis.util.backend_entry_points())
)

support_matrix = (
pd.DataFrame(support)
.assign(splits=lambda df: df.Operation.str.findall("[a-zA-Z_][a-zA-Z_0-9]*"))
.assign(
Category=lambda df: df.splits.str[-2],
Operation=lambda df: df.splits.str[-1],
)
.drop(["splits"], axis=1)
.set_index(["Category", "Operation"])
.sort_index()
)
all_visible_ops_count = len(support_matrix)
assert all_visible_ops_count

coverage = pd.Index(
support_matrix.sum()
.map(lambda n: f"{n} ({round(100 * n / all_visible_ops_count)}%)")
.T
)
support_matrix.columns = pd.MultiIndex.from_tuples(
list(zip(support_matrix.columns, coverage)), names=("Backend", "API coverage")
)
return support_matrix


if __name__ == "__main__":
print(make_support_matrix()) # noqa: T201
66 changes: 10 additions & 56 deletions docs/support_matrix.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,6 @@ hide:
- toc
---

```{python}
#| echo: false
import pandas as pd
import ibis
import ibis.expr.operations as ops
def get_backends(exclude=()):
entry_points = sorted(ep.name for ep in ibis.util.backend_entry_points())
return [
(backend, getattr(ibis, backend))
for backend in entry_points
if backend not in exclude
]
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)
public_ops = frozenset(get_leaf_classes(ops.Value))
support = {"Operation": [f"{op.__module__}.{op.__name__}" for op in public_ops]}
support.update(
(name, list(map(backend.has_operation, public_ops)))
for name, backend in get_backends()
)
support_matrix = (
pd.DataFrame(support)
.assign(splits=lambda df: df.Operation.str.findall("[a-zA-Z_][a-zA-Z_0-9]*"))
.assign(
Category=lambda df: df.splits.str[-2],
Operation=lambda df: df.splits.str[-1],
)
.drop(["splits"], axis=1)
.set_index(["Category", "Operation"])
.sort_index()
)
all_visible_ops_count = len(support_matrix)
coverage = pd.Index(
support_matrix.sum()
.map(lambda n: f"{n} ({round(100 * n / all_visible_ops_count)}%)")
.T
)
support_matrix.columns = pd.MultiIndex.from_tuples(
list(zip(support_matrix.columns, coverage)), names=("Backend", "API coverage")
)
support_matrix = support_matrix.replace({True: "✔", False: "🚫"})
```

## {height=25%}

::: {.card title="Welcome to the operation support matrix!"}
Expand Down Expand Up @@ -116,6 +61,15 @@ dict(value=sql_backends, color="green", icon="database")

```{python}
from itables import show
from support_matrix import make_support_matrix
show(support_matrix, ordering=False, paging=False, buttons=["copy", "excel", "csv"])
matrix = make_support_matrix()
show(
matrix.replace({True: "✔", False: "🚫"}),
ordering=False,
paging=False,
buttons=["copy", "excel", "csv"],
)
```

0 comments on commit 61525e4

Please sign in to comment.