Esempio n. 1
0
    def _validate_fill_value(self, value):
        if is_bool(value) or is_bool_dtype(value):
            # force conversion to object
            # so we don't lose the bools
            raise TypeError
        elif is_scalar(value) and isna(value):
            if is_valid_nat_for_dtype(value, self.dtype):
                value = self._na_value
                if self.dtype.kind != "f":
                    # raise so that caller can cast
                    raise TypeError
            else:
                # NaT, np.datetime64("NaT"), np.timedelta64("NaT")
                raise TypeError

        elif is_scalar(value):
            if not is_number(value):
                # e.g. datetime64, timedelta64, datetime, ...
                raise TypeError

            elif lib.is_complex(value):
                # at least until we have a ComplexIndx
                raise TypeError

            elif is_float(value) and self.dtype.kind != "f":
                if not value.is_integer():
                    raise TypeError
                value = int(value)

        return value
Esempio n. 2
0
    def _validate_fill_value(self, value):
        if is_bool(value) or is_bool_dtype(value):
            # force conversion to object
            # so we don't lose the bools
            raise TypeError
        elif is_scalar(value) and isna(value):
            if is_valid_nat_for_dtype(value, self.dtype):
                value = self._na_value
                if self.dtype.kind != "f":
                    # raise so that caller can cast
                    raise TypeError
            else:
                # NaT, np.datetime64("NaT"), np.timedelta64("NaT")
                raise TypeError

        elif is_scalar(value):
            if not is_number(value):
                # e.g. datetime64, timedelta64, datetime, ...
                raise TypeError

            elif lib.is_complex(value):
                # at least until we have a ComplexIndx
                raise TypeError

            elif is_float(value) and self.dtype.kind != "f":
                if not value.is_integer():
                    raise TypeError
                value = int(value)

        elif hasattr(value, "dtype") and value.dtype.kind in ["m", "M"]:
            # TODO: if we're checking arraylike here, do so systematically
            raise TypeError

        return value
Esempio n. 3
0
    def _validate_fill_value(self, value):
        """
        Convert value to be insertable to ndarray.
        """
        if is_bool(value) or is_bool_dtype(value):
            # force conversion to object
            # so we don't lose the bools
            raise TypeError
        elif isinstance(value, str) or lib.is_complex(value):
            raise TypeError

        return value
Esempio n. 4
0
    def _validate_fill_value(self, value):
        """
        Convert value to be insertable to ndarray.
        """
        if is_bool(value) or is_bool_dtype(value):
            # force conversion to object
            # so we don't lose the bools
            raise TypeError
        elif isinstance(value, str) or lib.is_complex(value):
            raise TypeError
        elif is_scalar(value) and isna(value):
            if is_valid_nat_for_dtype(value, self.dtype):
                value = self._na_value
            else:
                # NaT, np.datetime64("NaT"), np.timedelta64("NaT")
                raise TypeError

        return value