Beispiel #1
0
    def _dtype(self):
        lmeasure = discover(self.lhs).measure
        lty = getattr(lmeasure, 'ty', lmeasure)
        rmeasure = discover(self.rhs).measure
        rty = getattr(rmeasure, 'ty', rmeasure)
        if lty == datetime_:
            if isinstance(rty, DateTime):
                return optionify(lmeasure, rmeasure, timedelta_)
            if isinstance(rty, TimeDelta):
                return optionify(lmeasure, rmeasure, datetime_)
            else:
                raise TypeError(
                    'can only subtract timedelta or datetime from datetime', )

        return super(Sub, self)._dtype
Beispiel #2
0
    def _dtype(self):
        lmeasure = discover(self.lhs).measure
        rmeasure = discover(self.rhs).measure
        if not (isinstance(getattr(lmeasure, 'ty', lmeasure), String)):
            raise TypeError('can only interp strings got: %s' % lmeasure)

        return optionify(lmeasure, rmeasure, lmeasure)
Beispiel #3
0
 def _dtype(self):
     lhs, rhs = discover(self.lhs).measure, discover(self.rhs).measure
     is_unsigned = lhs in unsigned and rhs in unsigned
     max_width = max(lhs.itemsize, rhs.itemsize)
     prefix = 'u' if is_unsigned else ''
     measure = getattr(ct, '%sint%d' % (prefix, max_width * 8))
     return optionify(lhs, rhs, measure)
Beispiel #4
0
    def _dtype(self):
        lmeasure = discover(self.lhs).measure
        rmeasure = discover(self.rhs).measure
        if not (isinstance(getattr(lmeasure, 'ty', lmeasure), String)):
            raise TypeError('can only interp strings got: %s' % lmeasure)

        return optionify(lmeasure, rmeasure, lmeasure)
Beispiel #5
0
 def _dtype(self):
     lhs, rhs = discover(self.lhs).measure, discover(self.rhs).measure
     is_unsigned = lhs in unsigned and rhs in unsigned
     max_width = max(lhs.itemsize, rhs.itemsize)
     prefix = 'u' if is_unsigned else ''
     measure = getattr(ct, '%sint%d' % (prefix, max_width * 8))
     return optionify(lhs, rhs, measure)
Beispiel #6
0
    def _dtype(self):
        lmeasure = discover(self.lhs).measure
        lty = getattr(lmeasure, 'ty', lmeasure)
        rmeasure = discover(self.rhs).measure
        rty = getattr(rmeasure, 'ty', rmeasure)
        if lty == datetime_:
            if isinstance(rty, DateTime):
                return optionify(lmeasure, rmeasure, timedelta_)
            if isinstance(rty, TimeDelta):
                return optionify(lmeasure, rmeasure, datetime_)
            else:
                raise TypeError(
                    'can only subtract timedelta or datetime from datetime',
                )

        return super(Sub, self)._dtype
Beispiel #7
0
    def _dtype(self):
        lmeasure = discover(self.lhs).measure
        rmeasure = discover(self.rhs).measure
        if not (isinstance(getattr(lmeasure, 'ty', lmeasure), String)
                and getattr(rmeasure, 'ty', rmeasure) in integral):
            raise TypeError(
                'can only repeat strings by an integer amount, got: %s * %s' %
                (lmeasure, rmeasure), )

        return optionify(lmeasure, rmeasure, lmeasure)
Beispiel #8
0
    def _dtype(self):
        lmeasure = discover(self.lhs).measure
        rmeasure = discover(self.rhs).measure
        if not (isinstance(getattr(lmeasure, 'ty', lmeasure), String) and
                getattr(rmeasure, 'ty', rmeasure) in integral):
            raise TypeError(
                'can only repeat strings by an integer amount, got: %s * %s' %
                (lmeasure, rmeasure),
            )

        return optionify(lmeasure, rmeasure, lmeasure)
Beispiel #9
0
    def _dtype(self):
        lmeasure = discover(self.lhs).measure
        lty = getattr(lmeasure, 'ty', lmeasure)
        rmeasure = discover(self.rhs).measure
        rty = getattr(rmeasure, 'ty', rmeasure)
        if lmeasure == datetime_ and rmeasure == datetime_:
            raise TypeError('cannot add datetime to datetime')

        l_is_datetime = lty == datetime_
        if l_is_datetime or rty == datetime_:
            if l_is_datetime:
                other = rty
            else:
                other = lty
            if isinstance(other, TimeDelta):
                return optionify(lmeasure, rmeasure, datetime_)
            else:
                raise TypeError('can only add timedeltas to datetimes', )

        return super(Add, self)._dtype
Beispiel #10
0
    def _dtype(self):
        lmeasure = discover(self.lhs).measure
        lty = getattr(lmeasure, 'ty', lmeasure)
        rmeasure = discover(self.rhs).measure
        rty = getattr(rmeasure, 'ty', rmeasure)
        if lmeasure == datetime_ and rmeasure == datetime_:
            raise TypeError('cannot add datetime to datetime')

        l_is_datetime = lty == datetime_
        if l_is_datetime or rty == datetime_:
            if l_is_datetime:
                other = rty
            else:
                other = lty
            if isinstance(other, TimeDelta):
                return optionify(lmeasure, rmeasure, datetime_)
            else:
                raise TypeError(
                    'can only add timedeltas to datetimes',
                )

        return super(Add, self)._dtype
Beispiel #11
0
def test_option_in_parent():
    x = int64
    y = Option(float32)
    z = optionify(x, y, y)
    assert z == y
Beispiel #12
0
 def _dtype(self):
     lhs, rhs = discover(self.lhs).measure, discover(self.rhs).measure
     return optionify(lhs, rhs, ct.float64)
Beispiel #13
0
 def _dtype(self):
     lhs, rhs = discover(self.lhs).measure, discover(self.rhs).measure
     return optionify(lhs, rhs, ct.float64)