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)
| 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 | """ |
no test coverage detected