-
Notifications
You must be signed in to change notification settings - Fork 202
feat: Introduce testing.constructors module and a pytest plugin
#3552
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
FBruzzesi
wants to merge
84
commits into
main
Choose a base branch
from
feat/testing-constructors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,966
−1,250
Open
Changes from 48 commits
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
100ac3b
feat: pytest plugin
FBruzzesi 1fd776d
simplify a bit
FBruzzesi 6ba28de
Simplify narwhals codebase
FBruzzesi 7e2c50d
bulk tests change with minimal impact
FBruzzesi a6361f9
Adjust TPCH
FBruzzesi 8c0f27f
split testing plugin and constructors into multiple test files
FBruzzesi 24743ce
mix with Dan implementation
FBruzzesi 1e05a49
fixup and allow kwargs
FBruzzesi c55beaa
simplify pytest_plugin
FBruzzesi 879fb3e
merge main
FBruzzesi 7e05734
defer imports
FBruzzesi db4784e
adjust GHA accordingly
FBruzzesi 1ad6ffb
constructors module coverage
FBruzzesi c833b87
add makefile rule
FBruzzesi 380b7be
fix test deps
FBruzzesi 612b470
try with coverage run ... && coverage report
FBruzzesi af99861
fix(typing): WIP
FBruzzesi 6e01b9b
revert 7e2c50d8bf2205e27d04addb4199f64823af083f
FBruzzesi 81f41c9
forgot one file :(
FBruzzesi 92a2ab1
alias imports
FBruzzesi 9d9d0d2
fixup tests
FBruzzesi af31a60
try inline &&
FBruzzesi 06be300
c.__name__ -> str(c)
FBruzzesi e9b94bb
try with fail-under flag under report
FBruzzesi 2ac3da9
try no pytest-cov
FBruzzesi 0e313de
fixup command
FBruzzesi 6e09bfc
fixup pyarrow getitem
FBruzzesi 5b5f507
back to pytest-cov
FBruzzesi 11a8183
Act 1
FBruzzesi 3acdbac
fully remove ConstructorName
FBruzzesi 90d90c0
remove pytest-cov, coverage: run -> combine -> report
FBruzzesi b0fbd1b
add patch=subprocess option
FBruzzesi edb0263
pragma: no cover constructors as current main
FBruzzesi 06a6961
add patches to coveragepy
FBruzzesi 024640a
remove mapping hint in tests
FBruzzesi 7d127f7
rename base classes
FBruzzesi e5c192e
merge main
FBruzzesi 76b5851
rm execv patch flag
FBruzzesi e1749ac
addressing typing issues part 1
FBruzzesi df1afc3
add NativeIbis to v1 IntoDataFrame
FBruzzesi 21befee
match polars signature in assert_frame_equal to fix typing
FBruzzesi 96b6a44
try hack to define coverage patch flags dynamically
FBruzzesi 57a5f18
port fix from #3555
FBruzzesi ffc2166
fix: pytest on py3.14 ported wrong min coverage
FBruzzesi ffbf61a
Run join_test with eager frames as well
FBruzzesi 8042564
do not collect too early
FBruzzesi 25126ea
fixup join test part 2
FBruzzesi 024135a
test_join_duplicate_column_names fix
FBruzzesi e1d09e5
Adopt registry pattern, tackle a few other feedbacks
FBruzzesi e97f331
fixup typing and prepare_constructors regression
FBruzzesi e76e50d
fix __eq__
FBruzzesi b1da6a7
match is_nullable default
FBruzzesi bb6b042
fixup typevar default
FBruzzesi 32018b3
Fixup default backends parsing
FBruzzesi 37c1edb
no cover + GHA
FBruzzesi e811459
Merge branch 'main' into feat/testing-constructors
FBruzzesi 9712559
refactor: Rename exposed fixtures and pytest options (#3556)
FBruzzesi 3f6beb6
merge main, resolve conflicts
FBruzzesi 6355f0a
feat: Let constructor fixtures return narwhals object directly (#3569)
FBruzzesi 6faf05a
merge main
FBruzzesi b6ba91e
fixup testing.md
FBruzzesi 985eb40
merge main
FBruzzesi 73fd0fc
fixup _select_backends
FBruzzesi 141a537
modules as implementation of protocols
FBruzzesi 7144039
merge main
FBruzzesi 5f57dd1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6c7f625
fix up formatting and linting
FBruzzesi f909afb
fix up formatting and linting
FBruzzesi 8a605aa
Merge branch 'main' into feat/testing-constructors
FBruzzesi 496c7e5
merge main, hopefully solve conflicts
FBruzzesi fc34512
convert to native
FBruzzesi ef90f44
add cov_source flag in make command
FBruzzesi b1359d2
merge main, solve conflicts
FBruzzesi 13c6dde
constructors -> nw-backends
FBruzzesi d52403d
add available_default_cpu_backends (#3673)
EdAbati 62ba007
Refactor pytest_addoption with Edo suggestion
FBruzzesi 1db05c9
add test for _default_backend_ids NARWHALS_DEFAULT_BACKENDS path
FBruzzesi e18ca1c
add test for multiple narwhals fixtures at once
FBruzzesi 91a0fd4
rollback typing changes... as I cannot recall their reason
FBruzzesi ef3a00a
Move coverage patches for Windows users into Makefile
FBruzzesi 87cc74e
Rename is_nullable to nan_is_null
FBruzzesi 81f0c73
Apply most typing suggestions
FBruzzesi 2a92a22
merge main
FBruzzesi c36d780
Merge branch 'main' into feat/testing-constructors
FBruzzesi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,72 @@ | ||
| # `narwhals.testing` | ||
|
|
||
| ## Asserts | ||
|
|
||
| ::: narwhals.testing | ||
| handler: python | ||
| options: | ||
| members: | ||
| - assert_frame_equal | ||
| - assert_series_equal | ||
|
|
||
| ## `pytest` plugin | ||
|
|
||
| Narwhals register a pytest plugin that exposes parametrized fixtures with callables | ||
| to build native frames from a column-oriented python `dict`. | ||
|
|
||
| ### Available fixtures | ||
|
|
||
| | Fixture | Backends | | ||
| |---|---| | ||
| | `constructor` | every selected backend (eager + lazy) | | ||
| | `constructor_eager` | only eager backends | | ||
|
|
||
| The selection is controlled by two CLI options: | ||
|
|
||
| * `--constructors=pandas,polars[lazy],duckdb`: comma-separated list. | ||
| Defaults to [`DEFAULT_CONSTRUCTORS`][narwhals.testing.constructors.DEFAULT_CONSTRUCTORS] | ||
| intersected with the backends installed in the current environment. | ||
| * `--all-cpu-constructors`: shortcut for "every CPU backend that is installed". | ||
| * `--use-external-constructor`: Skip narwhals.testing's parametrisation and let | ||
| another plugin provide the `constructor*` fixtures. | ||
|
|
||
| Set the `NARWHALS_DEFAULT_CONSTRUCTORS` environment variable to override the default | ||
| list (useful e.g. when running under `cudf.pandas`). | ||
|
|
||
| ### Quick start | ||
|
|
||
| The plugin auto-loads as soon as you `pip install narwhals`. Just write a test: | ||
|
|
||
| ```python | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| import narwhals as nw | ||
|
|
||
| if TYPE_CHECKING: | ||
| from narwhals.testing.typing import ConstructorEager, Data | ||
|
|
||
|
|
||
| def test_shape(constructor_eager: ConstructorEager) -> None: | ||
| data: Data = {"x": [1, 2, 3]} | ||
| df = nw.from_native(constructor_eager(data), eager_only=True) | ||
| assert df.shape == (3, 1) | ||
| ``` | ||
|
|
||
| The fixtures are parametrised against every supported backend that is installed | ||
| in the current environment. Filter the matrix on the command line: | ||
|
|
||
| ```bash | ||
| pytest --constructors="pandas,polars[lazy]" | ||
| pytest --all-cpu-constructors | ||
| ``` | ||
|
|
||
| ### Type aliases | ||
|
|
||
| ::: narwhals.testing.typing | ||
| handler: python | ||
| options: | ||
| members: | ||
| - Constructor | ||
| - ConstructorEager | ||
| - ConstructorLazy | ||
| - Data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.