MCPcopy
hub / github.com/numpy/numpy / update

Method update

numpy/lib/_iotools.py:766–821  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 15

performance.pyFile · 0.80
dtypesMethod · 0.80
_set_printoptionsFunction · 0.80
array2stringFunction · 0.80
isdtypeFunction · 0.80
_methods.pyFile · 0.80
api_hashMethod · 0.80
merge_api_dictsFunction · 0.80
mainFunction · 0.80
test_scalar_interfaceMethod · 0.80
test_interface_nullptrFunction · 0.80
__init__Method · 0.80

Calls 4

_dtypeortypeMethod · 0.95
_getdtypeMethod · 0.95
allFunction · 0.85
funcFunction · 0.70

Tested by 4

test_scalar_interfaceMethod · 0.64
test_interface_nullptrFunction · 0.64
test_kwargsFunction · 0.64