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