Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Can't use formula as branch #14

Closed
alexpearce opened this issue Feb 3, 2016 · 4 comments
Closed

Can't use formula as branch #14

alexpearce opened this issue Feb 3, 2016 · 4 comments

Comments

@alexpearce
Copy link
Contributor

root_numpy supports using formula as branch names. For example:

>>> root_numpy.root2array('f.root', 'tree', branches=['sqrt(mass)'], stop=3)
array([(739.8708446958261,), (1225.6622271912993,), (1096.497904427192,)],
      dtype=[('sqrt(mass)', '<f8')])

root_pandas doesn't support this, because it pattern matches branch names, failing if a name in the branches argument doesn't match a TBranch in the TTree.

@ibab
Copy link
Collaborator

ibab commented Feb 3, 2016

Would you suggest that we silently ignore patterns that don't match and let root_numpy fail if it doesn't find something?

It seems like we can't have both branch name matching and formulas in branch names, as the * in a * b would apply to both things at once.

@alexpearce
Copy link
Contributor Author

It seems like we can't have both branch name matching and formulas in branch names, as the * in a * b would apply to both things at once.

Indeed. I really like the globbing and brace expansion, so I'd be sad to see that go.

Maybe if formulas had to be prefixed with some magic string? Like formula:sqrt(mass). Then anything with the prefix would be ignored by the expansion logic, and the prefix is stripped before being passed to root_numpy.

It's not ideal though, and would require explicit documentation (although the support for formula is isn't mentioned in the root_numpy.root2array docs…).

@ibab
Copy link
Collaborator

ibab commented Feb 3, 2016

A noexpand: prefix would make a lot of sense, especially for cases where your variable names contain braces and *.

Or there could just be a expand=False option in read_root that does it for all columns.
Then the user might have to call read_root several times (which shouldn't be too bad in terms of efficiency).

@alexpearce
Copy link
Contributor Author

👍 for noexpand:.

It's pretty obvious what noexpand: should do and why, whereas understanding an expand kwarg requires you understanding the internals a bit more.

alexpearce added a commit to alexpearce/root_pandas that referenced this issue May 9, 2016
root_numpy supports branch names to be formulas, such as 2*sqrt(x),
which are parsed by ROOT’s TFormula class.

The use of * by root_pandas for branch name matching conflicted with
this behaviour. This commit adds the NOEXPAND_PREFIX string, which
causes column names to skip the branch name matching mechanisms.

Closes scikit-hep#14.
alexpearce added a commit to alexpearce/root_pandas that referenced this issue May 11, 2016
root_numpy supports branch names to be formulas, such as 2*sqrt(x),
which are parsed by ROOT’s TFormula class.

The use of * by root_pandas for branch name matching conflicted with
this behaviour. This commit adds the NOEXPAND_PREFIX string, which
causes column names to skip the branch name matching mechanisms.

Closes scikit-hep#14.
@ibab ibab closed this as completed in d161d5a May 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants