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

feat: any Mapping assigned to a WritableDirectory is interpreted as a TTree or failure, no fall-through. #779

Merged
merged 1 commit into from Nov 11, 2022

Conversation

jpivarski
Copy link
Member

This is a change in policy. Now when anyone does

with uproot.recreate("file.root") as file:
    file["something"] = {"key": value}

it will always attempt to interpret the {"key": value} Mapping (any kind of Mapping) as a TTree. If any value cannot be interpreted as an array, it raises an error message that highlights the "key" name.

The old behavior was to give up on interpreting {"key": value} as a TTree, but keep open the possibility that it might be some other kind of writable data. In practice, there are no other types of writable data associated with Mapping, so the error message would be "unrecognized type cannot be written to a ROOT file: __dict__'".

What's worse, this error message depended on the state of the environment: if awkward is not installed, then Uproot can't check non-NumPy value to see if it might be interpretable as an Awkward Array (with ak.from_iter), so it failed with the above complaint about not recognizing the dict type, instead of saying that awkward needs to be pip-installed.

@agoose77
Copy link
Collaborator

In general, I'm all for tightening our input validation. This seems like a good policy change.

@agoose77 agoose77 merged commit 423ab07 into main Nov 11, 2022
@agoose77 agoose77 deleted the jpivarski/any-Mapping-attempts-to-write-as-TTree branch November 11, 2022 12:04
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.

Hidden error when saving pandas aaray to root file without awkward installed
2 participants