From a2c1a10e1d7220c55288a067a6ac9f19b9cf0104 Mon Sep 17 00:00:00 2001 From: Alessandro Miola <37796412+AlessandroMiola@users.noreply.github.com> Date: Mon, 7 Oct 2024 18:49:22 +0200 Subject: [PATCH] docs: add namespace methods in `check_api_reference.py` (#1144) * docs: add check on Series.dt methods being in api-reference * docs: add check on Series.cat methods being in api-reference * chore: remove extra blanks * docs: add check on documented, yet no longer existent methods on dtype * docs: add check on Expr.{cat, dt, name, str} methods being in api-reference * chore: remove useless check and move checks on Series.{cat, dt, str} higher up * docs: apply suggested changes --- utils/check_api_reference.py | 76 ++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/utils/check_api_reference.py b/utils/check_api_reference.py index 60e968a85..7bc590423 100644 --- a/utils/check_api_reference.py +++ b/utils/check_api_reference.py @@ -121,6 +121,31 @@ print(extra) # noqa: T201 ret = 1 +# Series.{cat, dt, str} methods +for namespace in NAMESPACES.difference({"name"}): + series_methods = [ + i + for i in getattr( + nw.from_native(pl.Series(), series_only=True), namespace + ).__dir__() + if not i[0].isupper() and i[0] != "_" + ] + with open(f"docs/api-reference/series_{namespace}.md") as fd: + content = fd.read() + documented = [ + remove_prefix(i, " - ") + for i in content.splitlines() + if i.startswith(" - ") and not i.startswith(" - _") + ] + if missing := set(series_methods).difference(documented): + print(f"Series.{namespace}: not documented") # noqa: T201 + print(missing) # noqa: T201 + ret = 1 + if extra := set(documented).difference(series_methods): + print(f"Series.{namespace}: outdated") # noqa: T201 + print(extra) # noqa: T201 + ret = 1 + # Expr methods expr_methods = [ i for i in nw.Expr(lambda: 0).__dir__() if not i[0].isupper() and i[0] != "_" @@ -141,6 +166,29 @@ print(extra) # noqa: T201 ret = 1 +# Expr.{cat, dt, name, str} methods +for namespace in NAMESPACES: + expr_methods = [ + i + for i in getattr(nw.Expr(lambda: 0), namespace).__dir__() + if not i[0].isupper() and i[0] != "_" + ] + with open(f"docs/api-reference/expr_{namespace}.md") as fd: + content = fd.read() + documented = [ + remove_prefix(i, " - ") + for i in content.splitlines() + if i.startswith(" - ") + ] + if missing := set(expr_methods).difference(documented): + print(f"Expr.{namespace}: not documented") # noqa: T201 + print(missing) # noqa: T201 + ret = 1 + if extra := set(documented).difference(expr_methods): + print(f"Expr.{namespace}: outdated") # noqa: T201 + print(extra) # noqa: T201 + ret = 1 + # DTypes dtypes = [ i for i in nw.dtypes.__dir__() if i[0].isupper() and not i.isupper() and i[0] != "_" @@ -156,32 +204,8 @@ print("Dtype: not documented") # noqa: T201 print(missing) # noqa: T201 ret = 1 - -# dt - -# Series.str methods -series_str_methods = [ - i - for i in nw.from_native(pl.Series(), series_only=True).str.__dir__() - if not i[0].isupper() and i[0] != "_" -] - -with open("docs/api-reference/series_str.md") as fd: - content = fd.read() - -documented = [ - remove_prefix(i, " - ") - for i in content.splitlines() - if i.startswith(" - ") and not i.startswith(" - _") -] - -if missing := set(series_str_methods).difference(documented): - print("Series.str: not documented") # noqa: T201 - print(missing) # noqa: T201 - ret = 1 - -if extra := set(documented).difference(series_str_methods): - print("Series.str: outdated") # noqa: T201 +if extra := set(documented).difference(dtypes): + print("Dtype: outdated") # noqa: T201 print(extra) # noqa: T201 ret = 1