neurokernel.plsel.SelectorParser¶
-
class
neurokernel.plsel.SelectorParser[source]¶ This class implements a parser for path-like selectors that can be associated with elements in a sequential data structure such as a Pandas DataFrame; in the latter case, each level of the selector corresponds to a level of a Pandas MultiIndex. An index level may either be a denoted by a string label (e.g., ‘foo’) or a numerical index (e.g., 0, 1, 2); a selector level may additionally be a list of strings (e.g., ‘[foo,bar]’) or integers (e.g., ‘[0,2,4]’) or continuous intervals (e.g., ‘[0:5]’). The ‘*’ symbol matches any value in a level, while a range with an open upper bound (e.g., ‘[5:]’) will match all integers greater than or equal to the lower bound.
Examples of valid selectors include
Selector Comments /foo/bar /foo+/bar equivalent to /foo/bar /foo/[qux,bar] /foo/bar[0] /foo/bar/[0] equivalent to /foo/bar[0] /foo/bar/0 equivalent to /foo/bar[0] /foo/bar[0,1] /foo/bar[0:5] /foo/*/baz /foo/*/baz[5] /foo/bar,/baz/qux (/foo,/bar)+/baz equivalent to /foo/baz,/bar/baz /[foo,bar].+/[0:2] equivalent to /foo[0],/bar[1] Notes
An empty string is deemed to be a valid selector.
Since there is no need to maintain multiple instances of the lexer/parser used to process path-like selectors, they are associated with the class rather than class instances; likewise, all of the class’ methods are classmethods.
Numerical indices in selectors are assumed to be zero-based. Intervals do not include the end element (i.e., like numpy, not like Pandas).
-
__init__()¶ x.__init__(…) initializes x; see help(type(x)) for signature
Methods
p_error(p)p_level(p)level : ASTERISK | INTEGER | INTEGER_SET | INTERVAL | STRING | STRING_SET p_selector_comma_selector(p)selector : selector COMMA selector p_selector_dotplus_selector(p)selector : selector DOTPLUS selector p_selector_level(p)selector : level p_selector_paren_selector(p)selector : LPAREN selector RPAREN p_selector_plus_selector(p)selector : selector PLUS selector p_selector_selector_level(p)selector : selector level p_selector_selector_plus_level(p)selector : selector PLUS level pad_parsed(selector[, pad_len, inplace])Pad token lists in a parsed selector to some maximum length. parse(selector[, pad_len])Parse a selector string into tokens. t_ASTERISK(t)/* t_COMMA(t), t_DOTPLUS(t).+ t_INTEGER(t)/?d+ t_INTEGER_SET(t)/?[(?:d+,?)+] t_INTERVAL(t)/?[d*:d*] t_LPAREN(t)( t_PLUS(t)+ t_RPAREN(t)) t_STRING(t)/[^*/[]():,.d][^+*/[]():,.]* t_STRING_SET(t)/?[(?:[^+*/[]():,.d][^+*/[]():,.]*,?)+] t_error(t)tokenize(selector)Tokenize a selector string. Attributes
lexerparsertokens-