Set StringConverter attributes directly. Parameters ---------- func : function Conversion function. default : any, optional Value to return by default, that is, when the string to be converted is flagged as missing. If not
(self, func, default=None, testing_value=None,
missing_values='', locked=False)
| 764 | self.iterupgrade(value) |
| 765 | |
| 766 | def update(self, func, default=None, testing_value=None, |
| 767 | missing_values='', locked=False): |
| 768 | """ |
| 769 | Set StringConverter attributes directly. |
| 770 | |
| 771 | Parameters |
| 772 | ---------- |
| 773 | func : function |
| 774 | Conversion function. |
| 775 | default : any, optional |
| 776 | Value to return by default, that is, when the string to be |
| 777 | converted is flagged as missing. If not given, |
| 778 | `StringConverter` tries to supply a reasonable default value. |
| 779 | testing_value : str, optional |
| 780 | A string representing a standard input value of the converter. |
| 781 | This string is used to help defining a reasonable default |
| 782 | value. |
| 783 | missing_values : {sequence of str, None}, optional |
| 784 | Sequence of strings indicating a missing value. If ``None``, then |
| 785 | the existing `missing_values` are cleared. The default is ``''``. |
| 786 | locked : bool, optional |
| 787 | Whether the StringConverter should be locked to prevent |
| 788 | automatic upgrade or not. Default is False. |
| 789 | |
| 790 | Notes |
| 791 | ----- |
| 792 | `update` takes the same parameters as the constructor of |
| 793 | `StringConverter`, except that `func` does not accept a `dtype` |
| 794 | whereas `dtype_or_func` in the constructor does. |
| 795 | |
| 796 | """ |
| 797 | self.func = func |
| 798 | self._locked = locked |
| 799 | |
| 800 | # Don't reset the default to None if we can avoid it |
| 801 | if default is not None: |
| 802 | self.default = default |
| 803 | self.type = self._dtypeortype(self._getdtype(default)) |
| 804 | else: |
| 805 | try: |
| 806 | tester = func(testing_value or '1') |
| 807 | except (TypeError, ValueError): |
| 808 | tester = None |
| 809 | self.type = self._dtypeortype(self._getdtype(tester)) |
| 810 | |
| 811 | # Add the missing values to the existing set or clear it. |
| 812 | if missing_values is None: |
| 813 | # Clear all missing values even though the ctor initializes it to |
| 814 | # set(['']) when the argument is None. |
| 815 | self.missing_values = set() |
| 816 | else: |
| 817 | if not np.iterable(missing_values): |
| 818 | missing_values = [missing_values] |
| 819 | if not all(isinstance(v, str) for v in missing_values): |
| 820 | raise TypeError("missing_values must be strings or unicode") |
| 821 | self.missing_values.update(missing_values) |
| 822 | |
| 823 |