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

Add support for variable scoping #21

Open
benkrikler opened this issue Oct 15, 2018 · 6 comments
Open

Add support for variable scoping #21

benkrikler opened this issue Oct 15, 2018 · 6 comments

Comments

@benkrikler
Copy link
Member

I've started looking into using this package for a project I'm working on. We'll want to be able to specify branches which might be nested within our trees, eg. branch.sub_branch. I've tested this briefly with version 0.0.7 of formulate though and I see that such variables cannot be identified:

$ python -m formulate --from-numexpr 'branch.sub_branch < 4' --variables
ERROR:formulate:TODO TRACEBACK: ('branch.sub_branch < 4', 6, 'Expected end of text')
ERROR:formulate:Error parsing: branch.sub_branch < 4
ERROR:formulate:                     ▲
ERROR:formulate:                     ┃
ERROR:formulate:                     ┗━━━━━━ Error here or shortly after

Would it be possible to add support for this? PyParsing has a specific helper method which might be useful here, delimitedList. I think the easiest for the user is to return a single variable in this case branch.sub_branch in the example above. That might mean just including the . in the definition of the Word for Variables?

@chrisburr
Copy link
Member

Yes, I definitely want to add support for this!

I don't use files like this very often, would you be able to share an example file? You can send it to me privately if you'd prefer by emailing me at christopher.burr with the domain being cern.ch.

@benkrikler
Copy link
Member Author

The samples I'm developing against are a bit private atm I'm afraid, but I think the mc10event.root file in uproot's testing samples is a good equivalent for what I'm looking at:
https://github.com/scikit-hep/uproot/blob/master/tests/samples/mc10events.root. Would that work for you?

@chrisburr
Copy link
Member

Thanks for file (and the delimitedList suggestion), I've added basic support now in v0.0.8. The example you gave now looks like this:

$ python -m formulate --from-numexpr 'branch.sub_branch < 4' --variables
branch.sub_branch

I don't work with files like this very often so please open issues if you run into more limitations. 😄

@eduardo-rodrigues
Copy link
Member

Same comment made at #22 - example above worth having in the README. Maybe use the file above for a test?

@benkrikler
Copy link
Member Author

Thanks for such a speedy implementation, Chris!

@marinang
Copy link
Member

marinang commented Oct 17, 2018

Hi I have a similar problem with with variables that have dot "." inside. See

capture d ecran 2018-10-17 a 10 56 21

As you can see, this is done with the last version of formulate, i.e v0.08.

The variables that bring problem are the isolation variables header_0.30_cc_asy_PT where 0.30 stands for the cone radius, this variables is automatically created by a LHCb tupletool.

An additional concern that I have, is how then the numpexpr conversion will be done?

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

No branches or pull requests

4 participants