Skip to content

refactor: Rename exposed fixtures and pytest options#3556

Open
FBruzzesi wants to merge 9 commits intofeat/testing-constructorsfrom
feat/testing-constructors-fixture-rename
Open

refactor: Rename exposed fixtures and pytest options#3556
FBruzzesi wants to merge 9 commits intofeat/testing-constructorsfrom
feat/testing-constructors-fixture-rename

Conversation

@FBruzzesi
Copy link
Copy Markdown
Member

@FBruzzesi FBruzzesi commented Apr 18, 2026

Description

This PR addresses the section from #3552:

In light of the CI failures for downstream projects, I also realized that having fixtures called constructor and constructor_eager is not really intuitive. I am happy to brainstorm better names for downstream users. And similarly the flags --all-cpu-constructors, --constructors. (*)

with the following renaming:

  • fixtures: nw_frame_constructor (eager + lazy), nw_eager_constructor (eager only), nw_pandas_like_constructor (pandas like only).
  • pytest options: --nw-backends, --all-nw-backends, --use-external-nw-backend

I know that nw.from_native(nw_frame_constructor(data)) is extremely verbose, but bear with me - I am also proposing to directly return nw.LazyFrame or nw.DataFrame from the nw_frame_constructor fixture.

From #3552:

If we find a way to achieve the following points, then I personally think we should do so, as we almost always run nw.from_native right after.

  • Distinguish between native frame and nw.from_native kwargs -> For this it's enough to provide it as different proper arguments in __call__, e.g. nw_kwargs, backend_kwargs.
  • How do we know which version a user would use? Should we require to pass either the Version.X or the namespace {nw, nw_v1, nw_v2} ? If we do so, I would argue that we must enforce it and never assume for the user. In my opinion nw_frame_constructor(data, version=nw) would still look better than nw.from_native(nw_frame_constructor(data))

TODO:

  • Update Docs

What type of PR is this? (check all applicable)

  • 💾 Refactor
  • ✨ Feature
  • 🐛 Bug Fix
  • 🔧 Optimization
  • 📝 Documentation
  • ✅ Test
  • 🐳 Other

@FBruzzesi FBruzzesi changed the title refactor: Rename fixtures and pytest options DO NOT MERGE, refactor: Rename fixtures and pytest options Apr 18, 2026
@FBruzzesi FBruzzesi changed the title DO NOT MERGE, refactor: Rename fixtures and pytest options refactor: Rename exposed fixtures and pytest options Apr 19, 2026
@dangotbanned
Copy link
Copy Markdown
Member

dangotbanned commented Apr 21, 2026

I know that nw.from_native(nw_frame_constructor(data)) is extremely verbose, but bear with me

Agreed, IMO this was already too much ceremony.
Like this blows up to almost double the size 😰

result = pl.DataFrame({"a": [1, 2, 3]}).select()
result = nw.from_native(constructor_eager({"a": [1, 2, 3]}), eager_only=True).select() 

I am also proposing to directly return nw.LazyFrame or nw.DataFrame from the nw_frame_constructor fixture.

👍 from me on skipping from_native.

Note

you probably already knew I was on board, I just wanted to make it more visible


To bikeshed on the naming some more:

  1. Is the nw_ prefix to avoid clobbering the fixture namespace?
    If so, pytest is pretty flexible in Overriding fixtures on various levels.
    Just seems like a problem that pytest would have a solution for hidden somewhere 😄
  2. If all of our fixtures are suffixed by _constructor, is that part not redundant?

Combining those two points, you'd get something like this, where the concepts are embedded in the types, rather than the names:

Mandatory plug for tests.plan

Made you click 😉

I'm still missing a frame fixture, but that would come eventually

@pytest.fixture
def lazyframe() -> LazyFrame: ...
@pytest.fixture
def dataframe() -> DataFrame: ...
@pytest.fixture
def series() -> Series: ...

LazyFrame: TypeAlias = Constructor[nwp.LazyFrame[Any]]
"""The type of the `lazyframe` fixture."""
DataFrame: TypeAlias = Constructor[nwp.DataFrame[Any, Any]]
"""The type of the `dataframe` fixture."""
Series: TypeAlias = Constructor[nwp.Series[Any]]
"""The type of the `series` fixture."""

You can still see more detail in an IDE if you want it:

Show IDE screenshot

image

Although another option is using a suffix for the type of the fixture, e.g.:

lazyframe: LazyFrame
lazyframe: LazyFrameFixture

Then you can alias the import if you want something shorter 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants