Skip to content
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

[ntuple] Improvements of Python interface and tests #17369

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

hahnjo
Copy link
Member

@hahnjo hahnjo commented Jan 7, 2025

As discussed around the RNTuple workshop, forbid calling RNTupleModel::CreateEntry() directly from Python. This allows to clone the passed RNTupleModel when creating a reader or writer, and avoid destructively passing the user argument.

Copy link

github-actions bot commented Jan 7, 2025

Test Results

    16 files      16 suites   3d 20h 39m 45s ⏱️
 2 694 tests  2 677 ✅ 0 💤 17 ❌
41 546 runs  41 484 ✅ 0 💤 62 ❌

For more details on these failures, see this check.

Results for commit baba720.

♻️ This comment has been updated with latest results.

Copy link
Member

@vepadulano vepadulano left a comment

Choose a reason for hiding this comment

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

Very nice thanks! Some minor comments from my side.

and type(maybe_model).__cpp_name__ == "ROOT::Experimental::RNTupleModel"
):
# In Python, the user cannot create REntries directly from a model, so we can safely clone it and avoid destructively passing the user argument.
maybe_model = maybe_model.Clone()
Copy link
Member

Choose a reason for hiding this comment

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

Here we might have a free opportunity for some extra error handling in an else branch letting the user know that only an RNTupleModel is accepted as input.

Copy link
Member Author

Choose a reason for hiding this comment

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

RNTupleReader::Open is overloaded, the first argument can also just be a string. In that case, the model is reconstructed from the on-disk header. I don't know if there is a better way to implement overloaded methods in Python...

Copy link
Member

Choose a reason for hiding this comment

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

I don't know if there is a better way to implement overloaded methods in Python...

The best approximation of it is https://docs.python.org/3/library/functools.html#functools.singledispatch , I don't know if it's worth using it for this particular PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

I also don't know how nicely this plays with cppyy. I'll leave the few extra cases as they are for the moment.

Comment on lines +124 to +127
# In Python, the user cannot create REntries directly from a model, so we can safely clone it and avoid destructively passing the user argument.
model = model.Clone()
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we want to have the same check as in _RNTupleWriter_Recreate here?

Copy link
Member Author

@hahnjo hahnjo Jan 8, 2025

Choose a reason for hiding this comment

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

We could, but for RNTupleWriter::Append the first model parameter is mandatory. For Recreate, the user can also pass a list of tuples (type, fieldname).

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

Successfully merging this pull request may close these issues.

3 participants