{"action":"created","issue":{"url":"https://api.github.com/repos/rootpy/root_numpy/issues/266","repository_url":"https://api.github.com/repos/rootpy/root_numpy","labels_url":"https://api.github.com/repos/rootpy/root_numpy/issues/266/labels{/name}","comments_url":"https://api.github.com/repos/rootpy/root_numpy/issues/266/comments","events_url":"https://api.github.com/repos/rootpy/root_numpy/issues/266/events","html_url":"https://github.com/rootpy/root_numpy/issues/266","id":172143308,"number":266,"title":"An efficient way to get formula expressions with multiplicity -1 as flat arrays","user":{"login":"ibab","id":890531,"avatar_url":"https://avatars.githubusercontent.com/u/890531?v=3","gravatar_id":"","url":"https://api.github.com/users/ibab","html_url":"https://github.com/ibab","followers_url":"https://api.github.com/users/ibab/followers","following_url":"https://api.github.com/users/ibab/following{/other_user}","gists_url":"https://api.github.com/users/ibab/gists{/gist_id}","starred_url":"https://api.github.com/users/ibab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ibab/subscriptions","organizations_url":"https://api.github.com/users/ibab/orgs","repos_url":"https://api.github.com/users/ibab/repos","events_url":"https://api.github.com/users/ibab/events{/privacy}","received_events_url":"https://api.github.com/users/ibab/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-08-19T14:26:12Z","updated_at":"2016-11-14T16:02:16Z","closed_at":null,"body":"In https://github.com/ibab/root_pandas/pull/30, we've realized that we need a way to extract the single-element lists that `root_numpy` returns if a formula expression has ROOT multiplicity -1 (meaning 0 or 1 elements per entry).\n\nOne way a flat array could be returned would be by using `NaN` whenever the number of elements is 0, and the value of the single element otherwise.\nUnfortunately, that would only work for floating point values (although returning 0 for integers might also be an option).\n\nInstead of changing the behaviour of `root_numpy`, it might also be possible to provide a helper function written in Cython that can index into the underlying per-entry arrays.\n"},"comment":{"url":"https://api.github.com/repos/rootpy/root_numpy/issues/comments/260376613","html_url":"https://github.com/rootpy/root_numpy/issues/266#issuecomment-260376613","issue_url":"https://api.github.com/repos/rootpy/root_numpy/issues/266","id":260376613,"user":{"login":"ndawe","id":202816,"avatar_url":"https://avatars.githubusercontent.com/u/202816?v=3","gravatar_id":"","url":"https://api.github.com/users/ndawe","html_url":"https://github.com/ndawe","followers_url":"https://api.github.com/users/ndawe/followers","following_url":"https://api.github.com/users/ndawe/following{/other_user}","gists_url":"https://api.github.com/users/ndawe/gists{/gist_id}","starred_url":"https://api.github.com/users/ndawe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ndawe/subscriptions","organizations_url":"https://api.github.com/users/ndawe/orgs","repos_url":"https://api.github.com/users/ndawe/repos","events_url":"https://api.github.com/users/ndawe/events{/privacy}","received_events_url":"https://api.github.com/users/ndawe/received_events","type":"User","site_admin":false},"created_at":"2016-11-14T16:02:16Z","updated_at":"2016-11-14T16:02:16Z","body":"I've been on the fence for a while, but had some time now to collect my thoughts. What do you think of the following options?\r\n                                                             \r\n1. Use a masked record array (with masked fields)                                      \r\nhttp://stackoverflow.com/questions/7217606/how-can-i-mask-elements-of-a-record-array-in-numpy\r\n**Pros:** potentially easy to implement. Fits naturally into numpy\r\n**Cons:** need to manage *two* arrays. The mask is an entirely separate array in memory\r\nand would be mostly wasteful if only a small fraction of fields need masking.   \r\n                                                                                 \r\n2. Add utility function to crop to fixed-length or impute with default values         \r\n**Pros:** maintain existing behaviour of root_numpy. I have a prototype that would need some clean up before placing in root_numpy.\r\n**Cons:** will be creating a copy of the array with fields modified (can't be done in-place)\r\n                                                                                   \r\n3. Specify cropped length and default value in tree2array's branches list with tuples:   \r\n  * multiplicity -1: 1 or 0 elements.\r\n  Impute (always yield single value) with ``(expr_string, default_value)`` in branches list\r\n  * multiplicity >=1: fixed and variable-length arrays.\r\n  Crop with ``(expr_string, length, default_value)`` in branches list. default_value is used when array is shorter than requested cropped length.\r\n\r\n  **Pros:** maintain existing behaviour of root_numpy. Just providing new functionality through the branches= argument. Performs operations in-place using no additional memory. Not copying the array... Explicitly specify default values for each case separately (can of course be different types).\r\n  **Cons:** any?\r\n\r\n\r\nPersonally I'm leaning toward option 3 since it is explicit, doesn't involve implementing our own string parsing on top of ROOT's TFormula, and doesn't involve unnecessary copying."}}
{"actor":{"display_login":"ndawe"}}