MCPcopy Index your code
hub / github.com/numpy/numpy / upgrade_mapper

Method upgrade_mapper

numpy/lib/_iotools.py:545–583  ·  view source on GitHub ↗

Upgrade the mapper of a StringConverter by adding a new function and its corresponding default. The input function (or sequence of functions) and its associated default value (if any) is inserted in penultimate position of the mapper. The corresponding type

(cls, func, default=None)

Source from the content-addressed store, hash-verified

543
544 @classmethod
545 def upgrade_mapper(cls, func, default=None):
546 """
547 Upgrade the mapper of a StringConverter by adding a new function and
548 its corresponding default.
549
550 The input function (or sequence of functions) and its associated
551 default value (if any) is inserted in penultimate position of the
552 mapper. The corresponding type is estimated from the dtype of the
553 default value.
554
555 Parameters
556 ----------
557 func : var
558 Function, or sequence of functions
559
560 Examples
561 --------
562 >>> import dateutil.parser
563 >>> import datetime
564 >>> dateparser = dateutil.parser.parse
565 >>> defaultdate = datetime.date(2000, 1, 1)
566 >>> StringConverter.upgrade_mapper(dateparser, default=defaultdate)
567 """
568 # Func is a single functions
569 if callable(func):
570 cls._mapper.insert(-1, (cls._getsubdtype(default), func, default))
571 return
572 elif hasattr(func, '__iter__'):
573 if isinstance(func[0], (tuple, list)):
574 for _ in func:
575 cls._mapper.insert(-1, _)
576 return
577 if default is None:
578 default = [None] * len(func)
579 else:
580 default = list(default)
581 default.append([None] * (len(func) - len(default)))
582 for fct, dft in zip(func, default):
583 cls._mapper.insert(-1, (cls._getsubdtype(dft), fct, dft))
584
585 @classmethod
586 def _find_map_entry(cls, dtype):

Callers 1

test_upgrademapperMethod · 0.80

Calls 1

_getsubdtypeMethod · 0.80

Tested by 1

test_upgrademapperMethod · 0.64