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

Refactor: Re enable and fix Ruff's PTH Check #443

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ lint.ignore = [
'PLR5501',
'PLR2004',
'PT011',
'PTH',
'RET505',
'S',
'SLF001',
Expand Down
6 changes: 3 additions & 3 deletions tests/frame/write_parquet_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import os
from pathlib import Path
from typing import Any

import pandas as pd
Expand All @@ -16,6 +16,6 @@
parse_version(pd.__version__) < parse_version("2.0.0"), reason="too old for pyarrow"
)
def test_write_parquet(constructor: Any, tmpdir: pytest.TempdirFactory) -> None:
path = str(tmpdir / "foo.parquet") # type: ignore[operator]
path = Path(str(tmpdir)) / "foo.parquet"
nw.from_native(constructor(data), eager_only=True).write_parquet(path)
assert os.path.exists(path)
assert path.exists()
31 changes: 20 additions & 11 deletions utils/check_api_reference.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import annotations

import os
import sys
from pathlib import Path

import polars as pl

Expand All @@ -11,16 +14,18 @@

# todo: make dtypes reference page as well
files = {remove_suffix(i, ".py") for i in os.listdir("narwhals")}
top_level_functions = [
top_level_functions: list[str] = [
i
for i in nw.__dir__()
if not i[0].isupper()
and i[0] != "_"
and i not in files
and i not in {"annotations", "DataFrame", "LazyFrame", "Series"}
]
with open("docs/api-reference/narwhals.md") as fd:
content = fd.read()

markdown_file = Path("docs/api-reference/narwhals.md")
content = markdown_file.read_text(encoding="UTF8")

documented = [
remove_prefix(i, " - ")
for i in content.splitlines()
Expand All @@ -40,8 +45,9 @@
for i in nw.DataFrame(pl.DataFrame(), is_polars=True, backend_version=(0,)).__dir__()
if not i[0].isupper() and i[0] != "_"
]
with open("docs/api-reference/dataframe.md") as fd:
content = fd.read()

api_document = Path("docs/api-reference/dataframe.md")
content = api_document.read_text(encoding="UTF8")
documented = [
remove_prefix(i, " - ")
for i in content.splitlines()
Expand All @@ -61,8 +67,9 @@
for i in nw.LazyFrame(pl.LazyFrame(), is_polars=True, backend_version=(0,)).__dir__()
if not i[0].isupper() and i[0] != "_"
]
with open("docs/api-reference/lazyframe.md") as fd:
content = fd.read()

lazyframe_document = Path("docs/api-reference/lazyframe.md")
content = lazyframe_document.read_text(encoding="UTF8")
documented = [
remove_prefix(i, " - ")
for i in content.splitlines()
Expand All @@ -82,8 +89,9 @@
for i in nw.Series(pl.Series(), backend_version=(1,), is_polars=True).__dir__()
if not i[0].isupper() and i[0] != "_"
]
with open("docs/api-reference/series.md") as fd:
content = fd.read()

series_document = Path("docs/api-reference/series.md")
content = series_document.read_text(encoding="UTF8")
documented = [
remove_prefix(i, " - ")
for i in content.splitlines()
Expand All @@ -105,8 +113,9 @@
top_level_functions = [
i for i in nw.Expr(lambda: 0).__dir__() if not i[0].isupper() and i[0] != "_"
]
with open("docs/api-reference/expressions.md") as fd:
content = fd.read()

expressions_document = Path("docs/api-reference/expressions.md")
content = expressions_document.read_text(encoding="UTF8")
documented = [
remove_prefix(i, " - ")
for i in content.splitlines()
Expand Down
17 changes: 9 additions & 8 deletions utils/generate_random_versions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import random
from pathlib import Path

PANDAS_VERSION = [
"1.0.5",
Expand Down Expand Up @@ -56,17 +57,17 @@
polars_version = random.choice(POLARS_VERSION)
pyarrow_version = random.choice(PYARROW_VERSION)

content = (
dependencies_content = (
f"pandas=={pandas_version}\npolars=={polars_version}\npyarrow=={pyarrow_version}\n"
)
with open("random-requirements.txt", "w") as fd:
fd.write(content)

with open("pyproject.toml") as fd:
content = fd.read()
content = content.replace(
Path("random-requirements.txt").write_text(dependencies_content, encoding="UTF-8")

pyproject_path = Path("pyproject.toml")
pyproject_content = pyproject_path.read_text(encoding="UTF-8")

updated_pyproject_content = pyproject_content.replace(
'filterwarnings = [\n "error",\n]',
"filterwarnings = [\n \"error\",\n 'ignore:distutils Version classes are deprecated:DeprecationWarning',\n]",
)
with open("pyproject.toml", "w") as fd:
fd.write(content)
pyproject_path.write_text(updated_pyproject_content, encoding="UTF-8")
Loading