Skip to content

feat: add behavior cls validation hook#3710

Merged
pfackeldey merged 4 commits intoscikit-hep:mainfrom
pfackeldey:behavior_validation
Nov 5, 2025
Merged

feat: add behavior cls validation hook#3710
pfackeldey merged 4 commits intoscikit-hep:mainfrom
pfackeldey:behavior_validation

Conversation

@pfackeldey
Copy link
Copy Markdown
Collaborator

This PR adds a way to run a validation method for behaviors, this helps to solve scikit-hep/vector#660.

A behavior may now implement the __awkward_validation__ method. It is run everytime awkward wants to update the class type of an highlevel array (which is on every instance creation, or 'in-place' mutation like __setitem__ or __delitem__ with fields. This implementation is non-invasive and safe in the sense that self is immutable (see its __setattr__ implementation) and is run right before the ak.validity_error check.

It is meant to be used for fast metadata checks, i.e. are certain fields present or not. This is not the right place to do O(n) array operations! <- I'll make this very explicit in the docs.

Also closes #1483.


Opening this in draft for now as I'm planning to add tests and docs tomorrow.

@ianna
Copy link
Copy Markdown
Member

ianna commented Nov 4, 2025

@ikrommyd - Quick note — for draft PRs, it’s usually best if the author merges main themselves, unless they’ve asked for help. Just keeps things cleaner for them 🙂

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 4, 2025

The documentation preview is ready to be viewed at http://preview.awkward-array.org.s3-website.us-east-1.amazonaws.com/PR3710

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 4, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.72%. Comparing base (b749e49) to head (e9c656e).
⚠️ Report is 463 commits behind head on main.

Files with missing lines Patch % Lines
src/awkward/highlevel.py 80.00% 2 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/awkward/highlevel.py 78.50% <80.00%> (+1.82%) ⬆️

... and 199 files with indirect coverage changes

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

@pfackeldey pfackeldey marked this pull request as ready for review November 5, 2025 10:43
@pfackeldey pfackeldey requested a review from ianna November 5, 2025 10:43
@pfackeldey
Copy link
Copy Markdown
Collaborator Author

@ianna this is now ready for a review :)

Copy link
Copy Markdown
Member

@ianna ianna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pfackeldey - This looks great! Please, go ahead and merge ti if you are done with it. Thanks.

Copy link
Copy Markdown
Member

@ianna ianna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@pfackeldey pfackeldey merged commit e74a848 into scikit-hep:main Nov 5, 2025
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array class validation

3 participants