Skip to content

fix: noxfile.py & better align it against GitHub Actions CI #2358

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
203 changes: 171 additions & 32 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from tempfile import NamedTemporaryFile
from typing import TYPE_CHECKING

import nox
Expand All @@ -8,80 +9,218 @@
from nox.sessions import Session

nox.options.default_venv_backend = "uv"
nox.options.reuse_venv = "yes"
nox.options.reuse_venv = "never"

PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12"]
PYTHON_VERSIONS = {
"pytest": ["3.8", "3.10", "3.11", "3.12", "3.13"],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this too. In CI we test on python 3.9 only in the random test.

Is it something deliberate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked back to this commit: e718d1f

My guess is that it mainly reduces the time it takes for tests to run without sacrificing too much validity.
Though I'll kick this one to @MarcoGorelli as well if he remembers.

"random": ["3.9"],
"minimum": "3.8",
"pretty_old": "3.8",
"not_so_old": "3.10",
"nightly": "3.13",
}


def run_common(session: Session, coverage_threshold: float) -> None:
if session.python == "3.8":
session.install("-e . --group dev-core")
elif session.python == "3.12":
session.install("-e .[dask,modin] --group dev-core --group extra")
else:
session.install("-e .[dask,modin,pyspark,ibis] --group dev-core --group extra")
@nox.session(python=PYTHON_VERSIONS["pytest"])
def pytest_coverage(session: Session) -> None:
pytest_cmd = [
"pytest",
"tests",
"--cov=narwhals",
"--cov=tests",
]

if session.python == "3.8":
session.install(
"-e", ".[pandas,polars,pyarrow]", "backports.zoneinfo", "--group", "tests"
)
session.run(
*pytest_cmd,
"--cov-fail-under=80",
"--constructors",
"pandas,pyarrow,polars[eager],polars[lazy]",
)

elif session.python in {"3.10", "3.12"}:
session.install(
"-e", ".[dask,modin]", "--group", "core-tests", "--group", "extra"
)
session.run(
*pytest_cmd,
"--cov-fail-under=95",
"--runslow",
"--constructors",
"pandas,pandas[nullable],pandas[pyarrow],pyarrow,modin[pyarrow],polars[eager],polars[lazy],dask,duckdb,sqlframe",
)

elif session.python in {"3.11", "3.13"}:
session.install(
"-e", ".[modin, dask]", "--group", "core-tests", "--group", "extra"
)
session.install("-U", "--pre", "duckdb")
if session.python != "3.13":
with NamedTemporaryFile() as f:
f.write(b"setuptools<78\n")
session.install("-b", f.name, "-e", ".[pyspark]")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why do we need to create a file for setuptools?

Maybe we could add the reason in a comment too?

Copy link
Member Author

@camriddell camriddell Apr 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was (naively) moved over from the current CI as I didn't think one could pipe to stdin within a subprocess like this. I also don't think nox provides a stdin channel to write to- though I would love to be mistaken on that front:

- name: install pyspark
run: echo "setuptools<78" | uv pip install -b - -e ".[pyspark]" --system
# PySpark is not yet available on Python3.12+
if: matrix.python-version != '3.13'

Perhaps @MarcoGorelli remembers something here?


if session.python == "3.11":
session.install("-e", ".[ibis]")

session.run(
*pytest_cmd,
"--cov-fail-under=100",
"--runslow",
"--all-cpu-constructors",
env={
"NARWHALS_POLARS_NEW_STREAMING": str(session.python == "3.11"),
},
)

if session.python == PYTHON_VERSIONS["pytest"][-1]:
session.run("pytest", "narwhals/", "--doctest-modules")


@nox.session(python=PYTHON_VERSIONS["minimum"])
def minimum(session: Session) -> None:
session.install(
"pandas==0.25.3",
"polars==0.20.3",
"numpy==1.17.5",
"pyarrow==11.0.0",
"pyarrow-stubs<17",
"scipy==1.5.0",
"scikit-learn==1.1.0",
"duckdb==1.0",
"tzdata",
"backports.zoneinfo",
)
session.install("-e", ".", "--group", "tests")
session.run(
"pytest",
"tests",
"--cov=narwhals",
"--cov=tests",
f"--cov-fail-under={coverage_threshold}",
"--cov-fail-under=50",
"--runslow",
"--constructors=pandas,pyarrow,polars[eager],polars[lazy]",
)

if session.python == "3.12":
session.run("pytest", "narwhals", "--doctest-modules")


@nox.session(python=PYTHON_VERSIONS) # type: ignore[misc]
def pytest_coverage(session: Session) -> None:
coverage_threshold = 85 if session.python == "3.8" else 100

run_common(session, coverage_threshold)


@nox.session(python=PYTHON_VERSIONS[0]) # type: ignore[misc]
@nox.parametrize("pandas_version", ["0.25.3", "1.1.5"]) # type: ignore[misc]
def min_and_old_versions(session: Session, pandas_version: str) -> None:
@nox.session(python=PYTHON_VERSIONS["pretty_old"])
def pretty_old(session: Session) -> None:
session.install(
f"pandas=={pandas_version}",
"pandas==1.1.5",
"polars==0.20.3",
"numpy==1.17.5",
"pyarrow==11.0.0",
"pyarrow-stubs<17",
"scipy==1.5.0",
"scikit-learn==1.1.0",
"duckdb==1.0",
"tzdata",
"backports.zoneinfo",
)
session.install("-e", ".", "--group", "tests")
session.run(
"pytest",
"tests",
"--cov=narwhals",
"--cov=tests",
"--cov-fail-under=50",
"--runslow",
"--constructors=pandas,pyarrow,polars[eager],polars[lazy]",
)


@nox.session(python=PYTHON_VERSIONS["not_so_old"])
def not_so_old(session: Session) -> None:
session.install(
"pandas==2.0.3",
"polars==0.20.8",
"numpy==1.24.4",
"pyarrow==15.0.0",
"pyarrow-stubs<17",
"scipy==1.8.0",
"scikit-learn==1.3.0",
"duckdb==1.0",
"dask[dataframe]==2024.10 ",
"tzdata",
)
if pandas_version == "1.1.5":
session.install("pyspark==3.3.0")
run_common(session, coverage_threshold=50)
session.install("-e", ".", "--group", "tests")
session.run(
"pytest",
"tests",
"--cov=narwhals",
"--cov=tests",
"--cov-fail-under=50",
"--runslow",
"--constructors=pandas,pyarrow,polars[eager],polars[lazy]",
)


@nox.session(python=PYTHON_VERSIONS[-1]) # type: ignore[misc]
@nox.session(python=PYTHON_VERSIONS["nightly"])
def nightly_versions(session: Session) -> None:
session.install("polars")
session.install("-e", ".", "--group", "tests")

session.install("--pre", "polars")

session.run("pip", "uninstall", "pandas", "--yes")
session.install( # pandas nightly
"--pre",
"--extra-index-url",
"https://pypi.anaconda.org/scientific-python-nightly-wheels/simple",
"pandas",
)

session.run("pip", "uninstall", "pyarrow", "--yes")
session.install( # pyarrow nightly
"--extra-index-url", "https://pypi.fury.io/arrow-nightlies/", "--pre", "pyarrow"
)

session.run("pip", "uninstall", "numpy", "--yes")
session.install( # numpy nightly
"--pre",
"--extra-index-url",
"https://pypi.anaconda.org/scientific-python-nightly-wheels/simple",
"numpy",
)

session.run("uv", "pip", "install", "pip")
session.run( # dask nightly
"pip",
"install",
"git+https://github.com/dask/distributed",
"git+https://github.com/dask/dask",
"git+https://github.com/dask/dask-expr",
)
run_common(session, coverage_threshold=50)

session.install("-U", "--pre", "duckdb") # duckdb nightly

session.run(
"pytest",
"tests",
"--cov=narwhals",
"--cov=tests",
"--cov-fail-under=50",
"--runslow",
"--constructors=pandas,pandas[nullable],pandas[pyarrow],pyarrow,polars[eager],polars[lazy],dask,duckdb",
)


@nox.session(python=PYTHON_VERSIONS["random"])
def random(session: Session) -> None:
from utils.generate_random_versions import requirements

with NamedTemporaryFile("w", suffix=".txt") as fd:
fd.write(requirements)
fd.flush()

session.install("-r", fd.name)
session.install("-e", ".", "--group", "tests")

session.run(
"pytest",
"tests",
"--cov=narwhals",
"--cov=tests",
"--cov-fail-under=80",
"--constructors=pandas,pyarrow,polars[eager],polars[lazy]",
)
22 changes: 10 additions & 12 deletions utils/generate_random_versions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import random
from textwrap import dedent

PANDAS_AND_NUMPY_VERSION = [
# ("1.0.5", "1.18.5"), # fails to build in CI # noqa: ERA001
Expand Down Expand Up @@ -57,16 +58,13 @@
pandas_version, numpy_version = random.choice(PANDAS_AND_NUMPY_VERSION)
polars_version = random.choice(POLARS_VERSION)
pyarrow_version = random.choice(PYARROW_VERSION)
requirements = dedent(f"""
pandas=={pandas_version}
numpy=={numpy_version}
polars=={polars_version}
pyarrow=={pyarrow_version}
""").lstrip()

content = f"pandas=={pandas_version}\nnumpy=={numpy_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(
'filterwarnings = [\n "error",\n]',
"filterwarnings = [\n \"error\",\n 'ignore:distutils Version classes are deprecated:DeprecationWarning',\n]",
)
Comment on lines -67 to -70
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this not needed anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah thank you! I was going to leave a comment for @MarcoGorelli about this.

The matching string doesn't exist in the pyproject.toml file any more (note the position of the closing square bracket ]) so this doesn't replace anything.

narwhals/pyproject.toml

Lines 204 to 227 in 4144497

[tool.pytest.ini_options]
norecursedirs = ['*.egg', '.*', '_darcs', 'build', 'CVS', 'dist', 'node_modules', 'venv', '{arch}', 'narwhals/_*']
testpaths = ["tests"]
filterwarnings = [
"error",
'ignore:.*defaulting to pandas implementation',
'ignore:.*implementation has mismatches with pandas',
'ignore:.*You are using pyarrow version',
# This warning was temporarily raised by pandas but then reverted.
'ignore:.*Passing a BlockManager to DataFrame:DeprecationWarning',
# This warning was temporarily raised by Polars but then reverted.
'ignore:.*The default coalesce behavior of left join will change:DeprecationWarning',
'ignore: unclosed <socket.socket',
'ignore:.*The distutils package is deprecated and slated for removal in Python 3.12:DeprecationWarning:pyspark',
'ignore:.*distutils Version classes are deprecated. Use packaging.version instead.*:DeprecationWarning:pyspark',
'ignore:.*is_datetime64tz_dtype is deprecated and will be removed in a future version.*:DeprecationWarning:pyspark',
# Warning raised by PyArrow nightly just by importing pandas
'ignore:.*Python binding for RankQuantileOptions not exposed:RuntimeWarning:pyarrow',
'ignore:.*pandas only supports SQLAlchemy:UserWarning:sqlframe',
'ignore:.*numpy.core is deprecated and has been renamed to numpy._core.*:DeprecationWarning:sqlframe',
"ignore:.*__array__ implementation doesn't accept a copy keyword, so passing copy=False failed:DeprecationWarning:modin",
# raised internally by pandas
"ignore:.*np.find_common_type is deprecated:DeprecationWarning:pandas",
]

with open("pyproject.toml", "w") as fd:
fd.write(content)
if __name__ == "__main__":
with open("random-requirements.txt", "w") as fd:
fd.write(requirements)
Loading