Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Removed class, added polars to the table, str.head and str.tail are a… #1801

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions utils/generate_backend_completeness.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Backend(NamedTuple):

DIRECTLY_IMPLEMENTED_METHODS = ["pipe", "implementation", "to_native"]

EXPR_STR_METHODS = ["tail", "head"]


def get_class_methods(kls: type[Any]) -> list[str]:
return [m[0] for m in inspect.getmembers(kls) if not m[0].startswith("_")]
Expand All @@ -79,6 +81,9 @@ def parse_module(module_name: str, backend: str, nw_class_name: str) -> list[str
else []
)

if module_name == "expr_str" and class_:
methods_ += EXPR_STR_METHODS

except ModuleNotFoundError:
methods_ = []

Expand All @@ -88,14 +93,19 @@ def parse_module(module_name: str, backend: str, nw_class_name: str) -> list[str
def render_table_and_write_to_output(
results: list[pl.DataFrame], title: str, output_filename: str
) -> None:
results = (
results: pl.DataFrame = (
pl.concat(results)
.with_columns(supported=pl.lit(":white_check_mark:"))
.pivot(on="Backend", values="supported", index=["Class", "Method"])
.pivot(on="Backend", values="supported", index=["Method"])
.filter(pl.col("narwhals").is_not_null())
.drop("narwhals")
.fill_null(":x:")
.sort("Class", "Method")
.sort("Method")
)

backends = [c for c in results.columns if c != "Method"] + ["polars"]
results = results.with_columns(polars=pl.lit(":white_check_mark:")).select(
"Method", *sorted(backends)
)

with pl.Config(
Expand Down Expand Up @@ -137,14 +147,11 @@ def get_backend_completeness_table() -> None:

nw_methods = get_class_methods(nw_class)

narwhals = pl.DataFrame(
{"Class": nw_class_name, "Backend": "narwhals", "Method": nw_methods}
)
narwhals = pl.DataFrame({"Backend": "narwhals", "Method": nw_methods})

backend_methods = [
pl.DataFrame(
{
"Class": nw_class_name,
"Backend": backend.name,
"Method": parse_module(
module_name,
Expand All @@ -171,7 +178,9 @@ def get_backend_completeness_table() -> None:
continue

render_table_and_write_to_output(
results=results, title=module_name.capitalize(), output_filename=module_name
results=results,
title=module_name.capitalize().replace("_", "."),
output_filename=module_name,
)


Expand Down
Loading