MCPcopy Create free account
hub / github.com/numpy/numpy / update

Method update

numpy/lib/_iotools.py:764–819  ·  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

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

Callers 15

_run_doctestsFunction · 0.80
sha256_of_fileFunction · 0.80
substituteMethod · 0.80
HTMLTemplateClass · 0.80
__call__Method · 0.80
fill_commandFunction · 0.80
performance.pyFile · 0.80
__init__.pyFile · 0.80
set_printoptionsFunction · 0.80
array2stringFunction · 0.80
__init__Method · 0.80
_methods.pyFile · 0.80

Calls 4

_dtypeortypeMethod · 0.95
_getdtypeMethod · 0.95
funcFunction · 0.70
allFunction · 0.50

Tested by 4

test_scalar_interfaceMethod · 0.64
test_kwargsFunction · 0.64
test_lazy_loadFunction · 0.64