Skip to content

Conversation

@johalnes
Copy link

PR description

This PR exposes assert_frame_schema_equal as a public Rust function and makes it available in Python.

Previously, Python users only had access to assert_frame_equal and assert_frame_not_equal. The underlying Rust function assert_frame_schema_equal has so far been private and used internally by those two assertions.

Making it public enables lightweight schema validation directly in Python, without relying on heavier validation frameworks like pandera. This can improve user feedback in data applications before persisting data to a database.

Closes #21215.

Review suggestions

  • A bit unsure about testing and necessary extent of testing. I've added two tests, mostly for documentation purposes. So far it seems to only be tested within assert_dataframe_equal
  • Didnt manage to build documentation in order to check doc string is OK

@johalnes johalnes changed the title feat: assert_frame_schema_eqaul available in py-polars feat: assert_frame_schema_equal available in py-polars Oct 14, 2025
@johalnes johalnes changed the title feat: assert_frame_schema_equal available in py-polars feat: Expose assert_frame_schema_equal in py-polars Oct 14, 2025
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars and removed title needs formatting labels Oct 14, 2025
@codecov
Copy link

codecov bot commented Oct 14, 2025

Codecov Report

❌ Patch coverage is 90.90909% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.73%. Comparing base (e006aad) to head (9e7c15a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
py-polars/src/polars/testing/asserts/frame.py 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #24869   +/-   ##
=======================================
  Coverage   81.73%   81.73%           
=======================================
  Files        1700     1700           
  Lines      233986   234005   +19     
  Branches     2993     2994    +1     
=======================================
+ Hits       191254   191270   +16     
- Misses      41971    41973    +2     
- Partials      761      762    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dsprenkels
Copy link
Collaborator

Bumping @coastalwhite, @ritchie46

This looks good to me

@coastalwhite
Copy link
Collaborator

I think the Python API and the Rust API are a bit different here. I would rather have a assert_schema_equal(left: Schema, right: Schema, ...) than a assert_frame_schema_equal.

This would also remove the problem with LazyFrame.collect_schema being implicitly triggered.

@johalnes
Copy link
Author

johalnes commented Oct 20, 2025

@coastalwhite the lazyfram.collect is a good catch. Didn't think that one trough! Thanks 😄

To understand a bit more of what you propose - do you suggest to create a completely rewrite of assert schema in Python? Or should I extend my PR to make assert_dataframe_schema_equal to actually be a thing wrapper that just get left/right_schema and then send it into a new rust function assert_schema_equal, which I then expose to the Python API instead of my current solution?

@johalnes
Copy link
Author

johalnes commented Oct 20, 2025

@coastalwhite Having thought on it a bit more. What do you think if I :

  • Move left_schema=left.schema into assert_dataframe_equal
  • Rename assert_dataframe_schema_equal to assert_schema_equal as you proposed, with schema as input type in rust
  • Renaming everything up into py-polars and changing to schema as input
  • Get the benefit of removing this collect part and simplifying the code since we know only get the schema

@ritchie46 ritchie46 force-pushed the main branch 3 times, most recently from 90ceb7b to e9fce55 Compare October 26, 2025 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars

Projects

None yet

Development

Successfully merging this pull request may close these issues.

assert_schemas_equal

3 participants