Exemplo n.º 1
0
 def test_combine_with_different_kinds(self):
     cases = [
         (T.day() + T.minute(), T.minute(1441)),
         (T.second() + T.millisecond(10), T.millisecond(1010)),
         (T.hour() + T.minute(5) + T.second(10), T.second(3910))
     ]
     self._check_cases(cases)
Exemplo n.º 2
0
    def test_cannot_upconvert(self):
        cases = [
            (T.day(), 'w'),
            (T.hour(), 'd'),
            (T.minute(), 'h'),
            (T.second(), 'm'),
            (T.second(), 'd'),
            (T.millisecond(), 's'),
            (T.microsecond(), 's'),
            (T.nanosecond(), 's'),
        ]

        for delta, target in cases:
            self.assertRaises(IbisError, delta.to_unit, target)
Exemplo n.º 3
0
    def test_cannot_upconvert(self):
        cases = [
            (T.day(), 'w'),
            (T.hour(), 'd'),
            (T.minute(), 'h'),
            (T.second(), 'm'),
            (T.second(), 'd'),
            (T.millisecond(), 's'),
            (T.microsecond(), 's'),
            (T.nanosecond(), 's'),
        ]

        for delta, target in cases:
            self.assertRaises(IbisError, delta.to_unit, target)
Exemplo n.º 4
0
    def test_upconvert(self):
        cases = [
            (T.day(14), 'w', T.week(2)),
            (T.hour(72), 'd', T.day(3)),
            (T.minute(240), 'h', T.hour(4)),
            (T.second(360), 'm', T.minute(6)),
            (T.second(3 * 86400), 'd', T.day(3)),
            (T.millisecond(5000), 's', T.second(5)),
            (T.microsecond(5000000), 's', T.second(5)),
            (T.nanosecond(5000000000), 's', T.second(5)),
        ]

        for offset, unit, expected in cases:
            result = offset.to_unit(unit)
            assert result.equals(expected)
Exemplo n.º 5
0
    def test_upconvert(self):
        cases = [
            (T.day(14), 'w', T.week(2)),
            (T.hour(72), 'd', T.day(3)),
            (T.minute(240), 'h', T.hour(4)),
            (T.second(360), 'm', T.minute(6)),
            (T.second(3 * 86400), 'd', T.day(3)),
            (T.millisecond(5000), 's', T.second(5)),
            (T.microsecond(5000000), 's', T.second(5)),
            (T.nanosecond(5000000000), 's', T.second(5)),
        ]

        for offset, unit, expected in cases:
            result = offset.to_unit(unit)
            assert result.equals(expected)
Exemplo n.º 6
0
    def test_downconvert_second_parts(self):
        K = 2

        sec = T.second(K)
        milli = T.millisecond(K)
        micro = T.microsecond(K)
        nano = T.nanosecond(K)

        cases = [(sec.to_unit('s'), T.second(K)),
                 (sec.to_unit('ms'), T.millisecond(K * 1000)),
                 (sec.to_unit('us'), T.microsecond(K * 1000000)),
                 (sec.to_unit('ns'), T.nanosecond(K * 1000000000)),
                 (milli.to_unit('ms'), T.millisecond(K)),
                 (milli.to_unit('us'), T.microsecond(K * 1000)),
                 (milli.to_unit('ns'), T.nanosecond(K * 1000000)),
                 (micro.to_unit('us'), T.microsecond(K)),
                 (micro.to_unit('ns'), T.nanosecond(K * 1000)),
                 (nano.to_unit('ns'), T.nanosecond(K))]
        self._check_cases(cases)
Exemplo n.º 7
0
    def test_downconvert_hours(self):
        K = 2
        offset = T.hour(K)

        cases = [(offset.to_unit('h'), T.hour(K)),
                 (offset.to_unit('m'), T.minute(K * 60)),
                 (offset.to_unit('s'), T.second(K * 3600)),
                 (offset.to_unit('ms'), T.millisecond(K * 3600000)),
                 (offset.to_unit('us'), T.microsecond(K * 3600000000)),
                 (offset.to_unit('ns'), T.nanosecond(K * 3600000000000))]
        self._check_cases(cases)
Exemplo n.º 8
0
 def test_timedelta_generic_api(self):
     cases = [
         (T.timedelta(weeks=2), T.week(2)),
         (T.timedelta(days=3), T.day(3)),
         (T.timedelta(hours=4), T.hour(4)),
         (T.timedelta(minutes=5), T.minute(5)),
         (T.timedelta(seconds=6), T.second(6)),
         (T.timedelta(milliseconds=7), T.millisecond(7)),
         (T.timedelta(microseconds=8), T.microsecond(8)),
         (T.timedelta(nanoseconds=9), T.nanosecond(9)),
     ]
     self._check_cases(cases)
Exemplo n.º 9
0
    def test_downconvert_second_parts(self):
        K = 2

        sec = T.second(K)
        milli = T.millisecond(K)
        micro = T.microsecond(K)
        nano = T.nanosecond(K)

        cases = [
            (sec.to_unit("s"), T.second(K)),
            (sec.to_unit("ms"), T.millisecond(K * 1000)),
            (sec.to_unit("us"), T.microsecond(K * 1000000)),
            (sec.to_unit("ns"), T.nanosecond(K * 1000000000)),
            (milli.to_unit("ms"), T.millisecond(K)),
            (milli.to_unit("us"), T.microsecond(K * 1000)),
            (milli.to_unit("ns"), T.nanosecond(K * 1000000)),
            (micro.to_unit("us"), T.microsecond(K)),
            (micro.to_unit("ns"), T.nanosecond(K * 1000)),
            (nano.to_unit("ns"), T.nanosecond(K)),
        ]
        self._check_cases(cases)
Exemplo n.º 10
0
 def test_timedelta_generic_api(self):
     cases = [
         (T.timedelta(weeks=2), T.week(2)),
         (T.timedelta(days=3), T.day(3)),
         (T.timedelta(hours=4), T.hour(4)),
         (T.timedelta(minutes=5), T.minute(5)),
         (T.timedelta(seconds=6), T.second(6)),
         (T.timedelta(milliseconds=7), T.millisecond(7)),
         (T.timedelta(microseconds=8), T.microsecond(8)),
         (T.timedelta(nanoseconds=9), T.nanosecond(9)),
     ]
     self._check_cases(cases)
Exemplo n.º 11
0
    def test_downconvert_hours(self):
        K = 2
        offset = T.hour(K)

        cases = [
            (offset.to_unit("h"), T.hour(K)),
            (offset.to_unit("m"), T.minute(K * 60)),
            (offset.to_unit("s"), T.second(K * 3600)),
            (offset.to_unit("ms"), T.millisecond(K * 3600000)),
            (offset.to_unit("us"), T.microsecond(K * 3600000000)),
            (offset.to_unit("ns"), T.nanosecond(K * 3600000000000L)),
        ]
        self._check_cases(cases)
Exemplo n.º 12
0
    def test_downconvert_hours(self):
        K = 2
        offset = T.hour(K)

        cases = [
            (offset.to_unit('h'), T.hour(K)),
            (offset.to_unit('m'), T.minute(K * 60)),
            (offset.to_unit('s'), T.second(K * 3600)),
            (offset.to_unit('ms'), T.millisecond(K * 3600000)),
            (offset.to_unit('us'), T.microsecond(K * 3600000000)),
            (offset.to_unit('ns'), T.nanosecond(K * 3600000000000))
        ]
        self._check_cases(cases)
Exemplo n.º 13
0
    def test_downconvert_day(self):
        K = 2

        week = T.week(K)
        day = T.day(K)

        cases = [(week.to_unit('d'), T.day(K * 7)),
                 (week.to_unit('h'), T.hour(K * 7 * 24)),
                 (day.to_unit('d'), T.day(K)),
                 (day.to_unit('h'), T.hour(K * 24)),
                 (day.to_unit('m'), T.minute(K * 1440)),
                 (day.to_unit('s'), T.second(K * 86400)),
                 (day.to_unit('ms'), T.millisecond(K * 86400000)),
                 (day.to_unit('us'), T.microsecond(K * 86400000000)),
                 (day.to_unit('ns'), T.nanosecond(K * 86400000000000))]
        self._check_cases(cases)
Exemplo n.º 14
0
    def test_downconvert_day(self):
        K = 2

        week = T.week(K)
        day = T.day(K)

        cases = [
            (week.to_unit("d"), T.day(K * 7)),
            (week.to_unit("h"), T.hour(K * 7 * 24)),
            (day.to_unit("d"), T.day(K)),
            (day.to_unit("h"), T.hour(K * 24)),
            (day.to_unit("m"), T.minute(K * 1440)),
            (day.to_unit("s"), T.second(K * 86400)),
            (day.to_unit("ms"), T.millisecond(K * 86400000)),
            (day.to_unit("us"), T.microsecond(K * 86400000000)),
            (day.to_unit("ns"), T.nanosecond(K * 86400000000000L)),
        ]
        self._check_cases(cases)
Exemplo n.º 15
0
    def test_downconvert_day(self):
        K = 2

        week = T.week(K)
        day = T.day(K)

        cases = [
            (week.to_unit('d'), T.day(K * 7)),
            (week.to_unit('h'), T.hour(K * 7 * 24)),

            (day.to_unit('d'), T.day(K)),
            (day.to_unit('h'), T.hour(K * 24)),
            (day.to_unit('m'), T.minute(K * 1440)),
            (day.to_unit('s'), T.second(K * 86400)),
            (day.to_unit('ms'), T.millisecond(K * 86400000)),
            (day.to_unit('us'), T.microsecond(K * 86400000000)),
            (day.to_unit('ns'), T.nanosecond(K * 86400000000000))
        ]
        self._check_cases(cases)
Exemplo n.º 16
0
 def test_repr(self):
     assert repr(T.day()) == '<Timedelta: 1 day>'
     assert repr(T.day(2)) == '<Timedelta: 2 days>'
     assert repr(T.year()) == '<Timedelta: 1 year>'
     assert repr(T.month(2)) == '<Timedelta: 2 months>'
     assert repr(T.second(40)) == '<Timedelta: 40 seconds>'
Exemplo n.º 17
0
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

from ibis.common import IbisError
import ibis.expr.operations as ops
import ibis.expr.types as ir
import ibis.expr.temporal as T


@pytest.mark.parametrize(('offset', 'unit', 'expected'), [
    (T.day(14), 'w', T.week(2)),
    (T.hour(72), 'd', T.day(3)),
    (T.minute(240), 'h', T.hour(4)),
    (T.second(360), 'm', T.minute(6)),
    (T.second(3 * 86400), 'd', T.day(3)),
    (T.millisecond(5000), 's', T.second(5)),
    (T.microsecond(5000000), 's', T.second(5)),
    (T.nanosecond(5000000000), 's', T.second(5)),
])
def test_upconvert(offset, unit, expected):
    result = offset.to_unit(unit)
    assert result.equals(expected)


def test_multiply():
    offset = T.day(2)

    assert (offset * 2).equals(T.day(4))
    assert (offset * (-2)).equals(T.day(-4))
Exemplo n.º 18
0
 def test_repr(self):
     assert repr(T.day()) == '<Timedelta: 1 day>'
     assert repr(T.day(2)) == '<Timedelta: 2 days>'
     assert repr(T.year()) == '<Timedelta: 1 year>'
     assert repr(T.month(2)) == '<Timedelta: 2 months>'
     assert repr(T.second(40)) == '<Timedelta: 40 seconds>'