MCPcopy
hub / github.com/quantopian/zipline / map_predicate

Method map_predicate

zipline/lib/labelarray.py:626–650  ·  view source on GitHub ↗

Map a function from str -> bool element-wise over ``self``. ``f`` will be applied exactly once to each non-missing unique value in ``self``. Missing values will always return False.

(self, f)

Source from the content-addressed store, hash-verified

624 )
625
626 def map_predicate(self, f):
627 """
628 Map a function from str -> bool element-wise over ``self``.
629
630 ``f`` will be applied exactly once to each non-missing unique value in
631 ``self``. Missing values will always return False.
632 """
633 # Functions passed to this are of type str -> bool. Don't ever call
634 # them on None, which is the only non-str value we ever store in
635 # categories.
636 if self.missing_value is None:
637 def f_to_use(x):
638 return False if x is None else f(x)
639 else:
640 f_to_use = f
641
642 # Call f on each unique value in our categories.
643 results = np.vectorize(f_to_use, otypes=[bool_dtype])(self.categories)
644
645 # missing_value should produce False no matter what
646 results[self.reverse_categories[self.missing_value]] = False
647
648 # unpack the results form each unique value into their corresponding
649 # locations in our indices.
650 return results[self.as_int_array()]
651
652 def map(self, f):
653 """

Callers 5

startswithMethod · 0.95
endswithMethod · 0.95
has_substringMethod · 0.95
matchesMethod · 0.95
element_ofMethod · 0.95

Calls 1

as_int_arrayMethod · 0.95

Tested by

no test coverage detected