narwhals icon indicating copy to clipboard operation
narwhals copied to clipboard

[Enh]: Provide `testing` module to enable downstream libraries testing

Open FBruzzesi opened this issue 1 year ago • 5 comments

We would like to learn about your use case. For example, if this feature is needed to adopt Narwhals in an open source project, could you please enter the link to it below?

  • This is a long shot, and I am not sure which (if any) and how other libraries do it.
  • For sure I could see adoption in scikit-lego

Please describe the purpose of the new feature or describe the problem to solve.

Provide a standard set of values and functionalities to generate tables for each backend we support

Suggest a solution if possible.

  • Have this as a separate library, let's say `narwhals-testing"
  • Have this in an internal module, which we can use for our testing purpose as well

If you have tried alternatives, please describe them below.

Manually create tables in downstream library :)

Additional information that may help us understand your needs.

No response

FBruzzesi avatar Aug 07 '24 19:08 FBruzzesi

Agree! I think @machow also wanted some testing functionality exposed for Shiny

MarcoGorelli avatar Aug 07 '24 21:08 MarcoGorelli

Adding some tracking here for what in my opinion means to close this PR:

  • [ ] nw.testing module
    • [ ] nw.testing.assert_series_equal - WIP in #2983
    • [ ] nw.testing.assert_frame_equal - blocked by #2983
  • [ ] nw.constructors module to provide fixture(s) to use in test suite of downstream libraries

FBruzzesi avatar Aug 26 '25 19:08 FBruzzesi

(There is a fine line between 'more sophisticated' and 'overly complicated' 😅 I hope to finish the draft soon)

EdAbati avatar Aug 27 '25 06:08 EdAbati

Originally posted by @elephaint in #2804

[!NOTE] Edited by @dangotbanned

Is this feature is needed to adopt Narwhals in an open source project?

At first hierarchicalforecast, in the future also our other open-source libraries in the Nixtla ecosystem

Describe the problem to solve

pandas.testing.assert_frame_equal and polars.testing.assert_frame_equal are really convenient when unit testing functionality.

Ideally, Narwhals has it too, so that we can abstract away from the dataframe provided and run the unit test on any desired dataframe engine.

Suggest a solution

Include wrappers for this testing functionality, or include native Narwhals testing functionality, e.g.

nw.testing.asserts.assert_frame_equal

dangotbanned avatar Sep 12 '25 08:09 dangotbanned

https://github.com/narwhals-dev/narwhals/issues/739#issuecomment-3225435754

nw.constructors module to provide fixture(s) to use in test suite of downstream libraries

@FBruzzesi did you mean nw.testing.constructors? Since the other stuff is in nw.testing.asserts 😄

Either way, I'm keen to see a child issue for that idea and discuss what's going on in yours and @EdAbati's and branches

dangotbanned avatar Sep 13 '25 10:09 dangotbanned