Skip to content

Commit 9712559

Browse files
authored
refactor: Rename exposed fixtures and pytest options (#3556)
1 parent e811459 commit 9712559

19 files changed

Lines changed: 208 additions & 188 deletions

File tree

.github/workflows/extremes.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
echo "$DEPS" | grep 'duckdb==1.1'
4747
- name: Run pytest
4848
run: |
49-
coverage run -m pytest tests --runslow --constructors=pandas,pyarrow,polars[eager],polars[lazy],duckdb
49+
coverage run -m pytest tests --runslow --nw-backends=pandas,pyarrow,polars[eager],polars[lazy],duckdb
5050
coverage combine
5151
coverage report --fail-under=50
5252
@@ -87,7 +87,7 @@ jobs:
8787
echo "$DEPS" | grep 'duckdb==1.2'
8888
- name: Run pytest
8989
run: |
90-
coverage run -m pytest tests --runslow --constructors=pandas,pyarrow,polars[eager],polars[lazy],duckdb
90+
coverage run -m pytest tests --runslow --nw-backends=pandas,pyarrow,polars[eager],polars[lazy],duckdb
9191
coverage combine
9292
coverage report --fail-under=50
9393
@@ -127,7 +127,7 @@ jobs:
127127
echo "$DEPS" | grep 'duckdb==1.3'
128128
- name: Run pytest
129129
run: |
130-
coverage run -m pytest tests --runslow --constructors=pandas,pyarrow,polars[eager],polars[lazy],dask,duckdb
130+
coverage run -m pytest tests --runslow --nw-backends=pandas,pyarrow,polars[eager],polars[lazy],dask,duckdb
131131
coverage combine
132132
coverage report --fail-under=50
133133
@@ -185,6 +185,6 @@ jobs:
185185
echo "$DEPS" | grep 'dask.*@'
186186
- name: Run pytest
187187
run: |
188-
coverage run -m pytest tests --runslow --constructors=pandas,pandas[nullable],pandas[pyarrow],pyarrow,polars[eager],polars[lazy],dask,duckdb
188+
coverage run -m pytest tests --runslow --nw-backends=pandas,pandas[nullable],pandas[pyarrow],pyarrow,polars[eager],polars[lazy],dask,duckdb
189189
coverage combine
190190
coverage report --fail-under=50

.github/workflows/pytest-ibis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ jobs:
3737
- name: show-deps
3838
run: uv pip freeze
3939
- name: Run pytest
40-
run: pytest tests --constructors ibis
40+
run: pytest tests --nw-backends ibis

.github/workflows/pytest-modin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ jobs:
3535
- name: show-deps
3636
run: uv pip freeze
3737
- name: Run pytest
38-
run: pytest tests --constructors modin[pyarrow]
38+
run: pytest tests --nw-backends modin[pyarrow]

.github/workflows/pytest-pyspark.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
run: uv pip freeze
4343
- name: Run pytest
4444
run: |
45-
coverage run -m pytest tests --runslow --constructors pyspark
45+
coverage run -m pytest tests --runslow --nw-backends pyspark
4646
coverage combine
4747
coverage report --fail-under=95 --include "narwhals/_spark_like/*"
4848
@@ -71,7 +71,7 @@ jobs:
7171
- name: show-deps
7272
run: uv pip freeze
7373
- name: Run pytest
74-
run: pytest tests --constructors pyspark
74+
run: pytest tests --nw-backends pyspark
7575

7676
pytest-pyspark-connect-constructor:
7777
strategy:
@@ -138,7 +138,7 @@ jobs:
138138
139139
- name: Run pytest
140140
run: |
141-
coverage run -m pytest tests --runslow --constructors "pyspark[connect]"
141+
coverage run -m pytest tests --runslow --nw-backends "pyspark[connect]"
142142
coverage combine
143143
coverage report --fail-under=95 --include="narwhals/_spark_like/*"
144144

.github/workflows/pytest.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
COVERAGE_PATCH_EXECV: ${{ matrix.os == 'windows-latest' && 'subprocess' || 'execv' }}
3838
COVERAGE_PATCH_FORK: ${{ matrix.os == 'windows-latest' && 'subprocess' || 'fork' }}
3939
run: |
40-
coverage run -m pytest tests --constructors=pandas,pyarrow,polars[eager],polars[lazy]
40+
coverage run -m pytest tests --nw-backends=pandas,pyarrow,polars[eager],polars[lazy]
4141
coverage combine
4242
coverage report --fail-under=75
4343
- name: install-test-plugin
@@ -74,7 +74,7 @@ jobs:
7474
run: uv pip freeze
7575
- name: Run pytest
7676
run: |
77-
coverage run -m pytest tests --runslow --constructors=pandas,pandas[nullable],pandas[pyarrow],pyarrow,polars[eager],polars[lazy],duckdb,sqlframe --durations=30
77+
coverage run -m pytest tests --runslow --nw-backends=pandas,pandas[nullable],pandas[pyarrow],pyarrow,polars[eager],polars[lazy],duckdb,sqlframe --durations=30
7878
coverage combine
7979
coverage report --fail-under=95
8080
@@ -108,7 +108,7 @@ jobs:
108108
run: uv pip freeze
109109
- name: Run pytest
110110
run: |
111-
coverage run -m pytest tests --runslow --constructors=pandas,pandas[nullable],pandas[pyarrow],pyarrow,polars[eager],polars[lazy],dask,duckdb,sqlframe --durations=30
111+
coverage run -m pytest tests --runslow --nw-backends=pandas,pandas[nullable],pandas[pyarrow],pyarrow,polars[eager],polars[lazy],dask,duckdb,sqlframe --durations=30
112112
coverage combine
113113
coverage report --fail-under=100
114114
- name: Run doctests
@@ -139,20 +139,20 @@ jobs:
139139
uv pip install -e ".[pandas]" --group tests
140140
uv pip freeze
141141
- name: Run pytest (pandas and pandas[nullable])
142-
run: pytest tests --runslow --constructors=pandas,pandas[nullable]
142+
run: pytest tests --runslow --nw-backends=pandas,pandas[nullable]
143143
- name: install-more-reqs
144144
run: |
145145
uv pip install -U pyarrow
146146
uv pip freeze
147147
- name: Run pytest (pandas[pyarrow] and pyarrow)
148-
run: pytest tests --runslow --constructors=pandas[pyarrow],pyarrow
148+
run: pytest tests --runslow --nw-backends=pandas[pyarrow],pyarrow
149149
- name: install-polars
150150
run: |
151151
uv pip uninstall pandas pyarrow
152152
uv pip install polars
153153
uv pip freeze
154154
- name: Run pytest (polars)
155-
run: pytest tests --runslow --constructors=polars[eager],polars[lazy]
155+
run: pytest tests --runslow --nw-backends=polars[eager],polars[lazy]
156156

157157
python-314:
158158
strategy:
@@ -177,7 +177,7 @@ jobs:
177177
run: uv pip freeze
178178
- name: Run pytest
179179
run: |
180-
coverage run -m pytest tests --runslow --constructors=pandas,pandas[nullable],pandas[pyarrow],pyarrow,polars[eager],polars[lazy],duckdb,sqlframe --durations=30
180+
coverage run -m pytest tests --runslow --nw-backends=pandas,pandas[nullable],pandas[pyarrow],pyarrow,polars[eager],polars[lazy],duckdb,sqlframe --durations=30
181181
coverage combine
182182
coverage report --fail-under=50
183183
@@ -206,6 +206,6 @@ jobs:
206206
run: uv pip freeze
207207
- name: Run pytest
208208
run: |
209-
coverage run -m pytest tests --runslow --durations=30 --constructors=pandas,pandas[nullable],pandas[pyarrow],pyarrow
209+
coverage run -m pytest tests --runslow --durations=30 --nw-backends=pandas,pandas[nullable],pandas[pyarrow],pyarrow
210210
coverage combine
211211
coverage report --fail-under=50

.github/workflows/random_ci_pytest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ jobs:
3737
run: uv pip freeze
3838
- name: Run pytest
3939
run: |
40-
coverage run -m pytest tests --constructors=pandas,pyarrow,polars[eager],polars[lazy]
40+
coverage run -m pytest tests --nw-backends=pandas,pyarrow,polars[eager],polars[lazy]
4141
coverage combine
4242
coverage report --fail-under=75

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ test: ## Run unittest
4949
--editable .[ibis,modin,pyspark] \
5050
--group core \
5151
--group tests
52-
$(VENV_BIN)/uv run --no-sync coverage run -m pytest tests --all-cpu-constructors --numprocesses=logical
52+
$(VENV_BIN)/uv run --no-sync coverage run -m pytest tests --all-nw-backends --numprocesses=logical
5353
$(VENV_BIN)/uv run --no-sync coverage combine
5454
$(VENV_BIN)/uv run --no-sync coverage report --fail-under=95

docs/api-reference/testing.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# `narwhals.testing`
22

3-
## Asserts
3+
## Assertions
44

55
::: narwhals.testing
66
handler: python
77
options:
8+
show_root_heading: false
9+
heading_level: 3
810
members:
911
- assert_frame_equal
1012
- assert_series_equal
@@ -18,19 +20,22 @@ to build native frames from a column-oriented python `dict`.
1820

1921
| Fixture | Backends |
2022
|---|---|
21-
| `constructor` | every selected backend (eager + lazy) |
22-
| `constructor_eager` | only eager backends |
23+
| `nw_frame_constructor` | every selected backend (eager + lazy) |
24+
| `nw_eager_constructor` | only eager backends |
25+
| `nw_pandas_like_constructor` | pandas-like backends |
2326

24-
The selection is controlled by two CLI options:
27+
### Pytest options
2528

26-
* `--constructors=pandas,polars[lazy],duckdb`: comma-separated list.
27-
Defaults to [`DEFAULT_CONSTRUCTORS`][narwhals.testing.constructors.DEFAULT_CONSTRUCTORS]
29+
The backend selection is controlled by the following CLI options:
30+
31+
* `--nw-backends=pandas,polars[lazy],duckdb`: comma-separated list.
32+
Defaults to [`DEFAULT_BACKENDS`][narwhals.testing.constructors.DEFAULT_BACKENDS]
2833
intersected with the backends installed in the current environment.
29-
* `--all-cpu-constructors`: shortcut for "every CPU backend that is installed".
30-
* `--use-external-constructor`: Skip narwhals.testing's parametrisation and let
34+
* `--nw-all-backends`: shortcut for "every **CPU** backend that is installed".
35+
* `--use-nw-external-constructor`: Skip narwhals.testing's parametrisation and let
3136
another plugin provide the `constructor*` fixtures.
3237

33-
Set the `NARWHALS_DEFAULT_CONSTRUCTORS` environment variable to override the default
38+
Set the `NARWHALS_DEFAULT_BACKENDS` environment variable to override the default
3439
list (useful e.g. when running under `cudf.pandas`).
3540

3641
### Quick start
@@ -43,30 +48,32 @@ from typing import TYPE_CHECKING
4348
import narwhals as nw
4449

4550
if TYPE_CHECKING:
46-
from narwhals.testing.typing import ConstructorEager, Data
51+
from narwhals.testing.typing import EagerFrameConstructor, Data
4752

4853

49-
def test_shape(constructor_eager: ConstructorEager) -> None:
54+
def test_shape(nw_eager_constructor: EagerFrameConstructor) -> None:
5055
data: Data = {"x": [1, 2, 3]}
51-
df = nw.from_native(constructor_eager(data), eager_only=True)
56+
df = nw.from_native(nw_eager_constructor(data), eager_only=True)
5257
assert df.shape == (3, 1)
5358
```
5459

5560
The fixtures are parametrised against every supported backend that is installed
5661
in the current environment. Filter the matrix on the command line:
5762

5863
```bash
59-
pytest --constructors="pandas,polars[lazy]"
60-
pytest --all-cpu-constructors
64+
pytest --nw-backends="pandas,polars[lazy]"
65+
pytest --all-nw-backends
6166
```
6267

63-
### Type aliases
68+
## Type aliases
6469

6570
::: narwhals.testing.typing
6671
handler: python
6772
options:
73+
show_root_heading: false
74+
heading_level: 3
6875
members:
69-
- Constructor
70-
- ConstructorEager
71-
- ConstructorLazy
7276
- Data
77+
- FrameConstructor
78+
- EagerFrameConstructor
79+
- LazyFrameConstructor

narwhals/testing/constructors.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ def my_backend_lazy_constructor(obj: Data, /, **kwds: Any) -> IntoLazyFrame:
6565

6666

6767
__all__ = (
68-
"available_constructors",
69-
"available_cpu_constructors",
68+
"available_backends",
69+
"available_cpu_backends",
7070
"frame_constructor",
71-
"get_constructor",
71+
"get_backend_constructor",
7272
"is_backend_available",
73-
"prepare_constructors",
73+
"prepare_backends",
7474
"pyspark_session",
7575
"sqlframe_session",
7676
)
@@ -464,7 +464,7 @@ def ibis_lazy_constructor(obj: Data, /, **kwds: Any) -> ibis.Table: # pragma: n
464464
return _ibis_backend().create_table(table_name, table, **kwds)
465465

466466

467-
DEFAULT_CONSTRUCTORS: frozenset[str] = frozenset(
467+
DEFAULT_BACKENDS: frozenset[str] = frozenset(
468468
{
469469
"pandas",
470470
"pandas[pyarrow]",
@@ -475,30 +475,30 @@ def ibis_lazy_constructor(obj: Data, /, **kwds: Any) -> ibis.Table: # pragma: n
475475
"ibis",
476476
}
477477
)
478-
"""Subset of constructors enabled by default for parametrised tests when the
479-
user does not pass `--constructors` (mirrors the historical Narwhals defaults).
478+
"""Subset of backends enabled by default for parametrised tests when the
479+
user does not pass `--nw-backends` (mirrors the historical Narwhals defaults).
480480
"""
481481

482482

483-
def available_constructors() -> frozenset[str]:
483+
def available_backends() -> frozenset[str]:
484484
"""Return the names of every constructor whose backend is importable.
485485
486486
Examples:
487-
>>> from narwhals.testing.constructors import available_constructors
488-
>>> "pandas" in available_constructors()
487+
>>> from narwhals.testing.constructors import available_backends
488+
>>> "pandas" in available_backends()
489489
True
490490
"""
491491
return frozenset(
492492
name for name, c in frame_constructor._registry.items() if c.is_available
493493
)
494494

495495

496-
def available_cpu_constructors() -> frozenset[str]: # pragma: no cover
496+
def available_cpu_backends() -> frozenset[str]: # pragma: no cover
497497
"""Return the names of every CPU constructor whose backend is importable.
498498
499499
Examples:
500-
>>> from narwhals.testing.constructors import available_cpu_constructors
501-
>>> "pandas" in available_cpu_constructors()
500+
>>> from narwhals.testing.constructors import available_cpu_backends
501+
>>> "pandas" in available_cpu_backends()
502502
True
503503
"""
504504
return frozenset(
@@ -524,14 +524,14 @@ def available_cpu_constructors() -> frozenset[str]: # pragma: no cover
524524

525525

526526
@overload
527-
def get_constructor(name: EagerName) -> frame_constructor[IntoDataFrame]: ...
527+
def get_backend_constructor(name: EagerName) -> frame_constructor[IntoDataFrame]: ...
528528
@overload
529-
def get_constructor(name: LazyName) -> frame_constructor[IntoLazyFrame]: ...
529+
def get_backend_constructor(name: LazyName) -> frame_constructor[IntoLazyFrame]: ...
530530
@overload
531-
def get_constructor(name: str) -> frame_constructor[IntoFrame]: ...
531+
def get_backend_constructor(name: str) -> frame_constructor[IntoFrame]: ...
532532

533533

534-
def get_constructor(name: str) -> frame_constructor[IntoFrame]:
534+
def get_backend_constructor(name: str) -> frame_constructor[IntoFrame]:
535535
"""Return the registered constructor for `name`.
536536
537537
Arguments:
@@ -542,8 +542,8 @@ def get_constructor(name: str) -> frame_constructor[IntoFrame]:
542542
ValueError: If `name` is not a registered constructor identifier.
543543
544544
Examples:
545-
>>> from narwhals.testing.constructors import get_constructor
546-
>>> get_constructor("pandas")
545+
>>> from narwhals.testing.constructors import get_backend_constructor
546+
>>> get_backend_constructor("pandas")
547547
frame_constructor(name='pandas')
548548
"""
549549
try:
@@ -554,7 +554,7 @@ def get_constructor(name: str) -> frame_constructor[IntoFrame]:
554554
raise ValueError(msg) from exc
555555

556556

557-
def prepare_constructors(
557+
def prepare_backends(
558558
*, include: Iterable[str] | None = None, exclude: Iterable[str] | None = None
559559
) -> list[frame_constructor[IntoFrame]]:
560560
"""Return available constructors, optionally filtered.
@@ -563,14 +563,14 @@ def prepare_constructors(
563563
`exclude` is given precedence in the selection.
564564
565565
Arguments:
566-
include: If given, only return constructors whose name is in this set.
567-
exclude: If given, remove constructors whose name is in this set.
566+
include: If given, only return backends whose name is in this set.
567+
exclude: If given, remove backends whose name is in this set.
568568
569569
Examples:
570-
>>> from narwhals.testing.constructors import prepare_constructors
571-
>>> constructors = prepare_constructors(include=["pandas", "polars[eager]"])
570+
>>> from narwhals.testing.constructors import prepare_backends
571+
>>> backends = prepare_backends(include=["pandas", "polars[eager]"])
572572
"""
573-
available = available_constructors()
573+
available = available_backends()
574574
candidates: list[frame_constructor[Any]] = [
575575
c for name, c in frame_constructor._registry.items() if name in available
576576
]

0 commit comments

Comments
 (0)