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

Method __init__

numpy/lib/_iotools.py:597–668  ·  view source on GitHub ↗
(self, dtype_or_func=None, default=None, missing_values=None,
                 locked=False)

Source from the content-addressed store, hash-verified

595 raise LookupError
596
597 def __init__(self, dtype_or_func=None, default=None, missing_values=None,
598 locked=False):
599 # Defines a lock for upgrade
600 self._locked = bool(locked)
601 # No input dtype: minimal initialization
602 if dtype_or_func is None:
603 self.func = str2bool
604 self._status = 0
605 self.default = default or False
606 dtype = np.dtype('bool')
607 else:
608 # Is the input a np.dtype ?
609 try:
610 self.func = None
611 dtype = np.dtype(dtype_or_func)
612 except TypeError:
613 # dtype_or_func must be a function, then
614 if not hasattr(dtype_or_func, '__call__'):
615 errmsg = ("The input argument `dtype` is neither a"
616 " function nor a dtype (got '%s' instead)")
617 raise TypeError(errmsg % type(dtype_or_func))
618 # Set the function
619 self.func = dtype_or_func
620 # If we don't have a default, try to guess it or set it to
621 # None
622 if default is None:
623 try:
624 default = self.func('0')
625 except ValueError:
626 default = None
627 dtype = self._getdtype(default)
628
629 # find the best match in our mapper
630 try:
631 self._status, (_, func, default_def) = self._find_map_entry(dtype)
632 except LookupError:
633 # no match
634 self.default = default
635 _, func, _ = self._mapper[-1]
636 self._status = 0
637 else:
638 # use the found default only if we did not already have one
639 if default is None:
640 self.default = default_def
641 else:
642 self.default = default
643
644 # If the input was a dtype, set the function to the last we saw
645 if self.func is None:
646 self.func = func
647
648 # If the status is 1 (int), change the function to
649 # something more robust.
650 if self.func == self._mapper[1][1]:
651 if issubclass(dtype.type, np.uint64):
652 self.func = np.uint64
653 elif issubclass(dtype.type, np.int64):
654 self.func = np.int64

Callers

nothing calls this directly

Calls 6

_getdtypeMethod · 0.95
_find_map_entryMethod · 0.95
_dtypeortypeMethod · 0.95
dtypeMethod · 0.45
funcMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected