Exemplo n.º 1
0
 def test_timedelta_conversions(self):
     self.assertEqual(ct(timedelta(seconds=1)),
                      np.timedelta64(1, 's').astype('m8[ns]'))
     self.assertEqual(ct(timedelta(microseconds=1)),
                      np.timedelta64(1, 'us').astype('m8[ns]'))
     self.assertEqual(ct(timedelta(days=1)),
                      np.timedelta64(1, 'D').astype('m8[ns]'))
Exemplo n.º 2
0
    def test_full_format_converters(self):
        def conv(v):
            return v.astype('m8[ns]')

        d1 = np.timedelta64(1, 'D')

        self.assertEqual(ct('1days'), conv(d1))
        self.assertEqual(ct('1days,'), conv(d1))
        self.assertEqual(ct('- 1days,'), -conv(d1))

        self.assertEqual(ct('00:00:01'), conv(np.timedelta64(1, 's')))
        self.assertEqual(ct('06:00:01'), conv(
            np.timedelta64(6 * 3600 + 1, 's')))
        self.assertEqual(ct('06:00:01.0'), conv(
            np.timedelta64(6 * 3600 + 1, 's')))
        self.assertEqual(ct('06:00:01.01'), conv(
            np.timedelta64(1000 * (6 * 3600 + 1) + 10, 'ms')))

        self.assertEqual(ct('- 1days, 00:00:01'),
                         conv(-d1 + np.timedelta64(1, 's')))
        self.assertEqual(ct('1days, 06:00:01'), conv(
            d1 + np.timedelta64(6 * 3600 + 1, 's')))
        self.assertEqual(ct('1days, 06:00:01.01'), conv(
            d1 + np.timedelta64(1000 * (6 * 3600 + 1) + 10, 'ms')))

        # invalid
        self.assertRaises(ValueError, ct, '- 1days, 00')
Exemplo n.º 3
0
    def test_numeric_conversions(self):
        self.assertEqual(ct(0), np.timedelta64(0,'ns'))
        self.assertEqual(ct(10), np.timedelta64(10,'ns'))
        self.assertEqual(ct(10,unit='ns'), np.timedelta64(10,'ns').astype('m8[ns]'))

        self.assertEqual(ct(10,unit='us'), np.timedelta64(10,'us').astype('m8[ns]'))
        self.assertEqual(ct(10,unit='ms'), np.timedelta64(10,'ms').astype('m8[ns]'))
        self.assertEqual(ct(10,unit='s'), np.timedelta64(10,'s').astype('m8[ns]'))
        self.assertEqual(ct(10,unit='d'), np.timedelta64(10,'D').astype('m8[ns]'))
Exemplo n.º 4
0
    def test_numeric_conversions(self):
        self.assertEqual(ct(0), np.timedelta64(0, "ns"))
        self.assertEqual(ct(10), np.timedelta64(10, "ns"))
        self.assertEqual(ct(10, unit="ns"), np.timedelta64(10, "ns").astype("m8[ns]"))

        self.assertEqual(ct(10, unit="us"), np.timedelta64(10, "us").astype("m8[ns]"))
        self.assertEqual(ct(10, unit="ms"), np.timedelta64(10, "ms").astype("m8[ns]"))
        self.assertEqual(ct(10, unit="s"), np.timedelta64(10, "s").astype("m8[ns]"))
        self.assertEqual(ct(10, unit="d"), np.timedelta64(10, "D").astype("m8[ns]"))
Exemplo n.º 5
0
    def test_full_format_converters(self):
        def conv(v):
            return v.astype("m8[ns]")

        d1 = np.timedelta64(1, "D")

        self.assertEqual(ct("1days"), conv(d1))
        self.assertEqual(ct("1days,"), conv(d1))
        self.assertEqual(ct("- 1days,"), -conv(d1))

        self.assertEqual(ct("00:00:01"), conv(np.timedelta64(1, "s")))
        self.assertEqual(ct("06:00:01"), conv(np.timedelta64(6 * 3600 + 1, "s")))
        self.assertEqual(ct("06:00:01.0"), conv(np.timedelta64(6 * 3600 + 1, "s")))
        self.assertEqual(ct("06:00:01.01"), conv(np.timedelta64(1000 * (6 * 3600 + 1) + 10, "ms")))

        self.assertEqual(ct("- 1days, 00:00:01"), conv(-d1 + np.timedelta64(1, "s")))
        self.assertEqual(ct("1days, 06:00:01"), conv(d1 + np.timedelta64(6 * 3600 + 1, "s")))
        self.assertEqual(ct("1days, 06:00:01.01"), conv(d1 + np.timedelta64(1000 * (6 * 3600 + 1) + 10, "ms")))

        # invalid
        self.assertRaises(ValueError, ct, "- 1days, 00")
Exemplo n.º 6
0
    def test_numeric_conversions(self):
        _skip_if_numpy_not_friendly()

        self.assert_(ct(0) == np.timedelta64(0,'ns'))
        self.assert_(ct(10) == np.timedelta64(10,'ns'))
        self.assert_(ct(10,unit='ns') == np.timedelta64(10,'ns').astype('m8[ns]'))

        self.assert_(ct(10,unit='us') == np.timedelta64(10,'us').astype('m8[ns]'))
        self.assert_(ct(10,unit='ms') == np.timedelta64(10,'ms').astype('m8[ns]'))
        self.assert_(ct(10,unit='s') == np.timedelta64(10,'s').astype('m8[ns]'))
        self.assert_(ct(10,unit='d') == np.timedelta64(10,'D').astype('m8[ns]'))
Exemplo n.º 7
0
    def test_numeric_conversions(self):
        _skip_if_numpy_not_friendly()

        self.assert_(ct(0) == np.timedelta64(0, "ns"))
        self.assert_(ct(10) == np.timedelta64(10, "ns"))
        self.assert_(ct(10, unit="ns") == np.timedelta64(10, "ns").astype("m8[ns]"))

        self.assert_(ct(10, unit="us") == np.timedelta64(10, "us").astype("m8[ns]"))
        self.assert_(ct(10, unit="ms") == np.timedelta64(10, "ms").astype("m8[ns]"))
        self.assert_(ct(10, unit="s") == np.timedelta64(10, "s").astype("m8[ns]"))
        self.assert_(ct(10, unit="d") == np.timedelta64(10, "D").astype("m8[ns]"))
Exemplo n.º 8
0
    def test_full_format_converters(self):
        _skip_if_numpy_not_friendly()

        def conv(v):
            return v.astype('m8[ns]')
        d1 = np.timedelta64(1,'D')

        self.assert_(ct('1days') == conv(d1))
        self.assert_(ct('1days,') == conv(d1))
        self.assert_(ct('- 1days,') == -conv(d1))

        self.assert_(ct('00:00:01') == conv(np.timedelta64(1,'s')))
        self.assert_(ct('06:00:01') == conv(np.timedelta64(6*3600+1,'s')))
        self.assert_(ct('06:00:01.0') == conv(np.timedelta64(6*3600+1,'s')))
        self.assert_(ct('06:00:01.01') == conv(np.timedelta64(1000*(6*3600+1)+10,'ms')))

        self.assert_(ct('- 1days, 00:00:01') == -conv(d1+np.timedelta64(1,'s')))
        self.assert_(ct('1days, 06:00:01') == conv(d1+np.timedelta64(6*3600+1,'s')))
        self.assert_(ct('1days, 06:00:01.01') == conv(d1+np.timedelta64(1000*(6*3600+1)+10,'ms')))

        # invalid
        self.assertRaises(ValueError, ct, '- 1days, 00')
Exemplo n.º 9
0
    def test_full_format_converters(self):
        _skip_if_numpy_not_friendly()

        def conv(v):
            return v.astype("m8[ns]")

        d1 = np.timedelta64(1, "D")

        self.assert_(ct("1days") == conv(d1))
        self.assert_(ct("1days,") == conv(d1))
        self.assert_(ct("- 1days,") == -conv(d1))

        self.assert_(ct("00:00:01") == conv(np.timedelta64(1, "s")))
        self.assert_(ct("06:00:01") == conv(np.timedelta64(6 * 3600 + 1, "s")))
        self.assert_(ct("06:00:01.0") == conv(np.timedelta64(6 * 3600 + 1, "s")))
        self.assert_(ct("06:00:01.01") == conv(np.timedelta64(1000 * (6 * 3600 + 1) + 10, "ms")))

        self.assert_(ct("- 1days, 00:00:01") == -conv(d1 + np.timedelta64(1, "s")))
        self.assert_(ct("1days, 06:00:01") == conv(d1 + np.timedelta64(6 * 3600 + 1, "s")))
        self.assert_(ct("1days, 06:00:01.01") == conv(d1 + np.timedelta64(1000 * (6 * 3600 + 1) + 10, "ms")))

        # invalid
        self.assertRaises(ValueError, ct, "- 1days, 00")
Exemplo n.º 10
0
    def test_timedelta_conversions(self):
        _skip_if_numpy_not_friendly()

        self.assert_(ct(timedelta(seconds=1)) == np.timedelta64(1,'s').astype('m8[ns]'))
        self.assert_(ct(timedelta(microseconds=1)) == np.timedelta64(1,'us').astype('m8[ns]'))
        self.assert_(ct(timedelta(days=1)) == np.timedelta64(1,'D').astype('m8[ns]'))
Exemplo n.º 11
0
    def test_timedelta_conversions(self):
        _skip_if_numpy_not_friendly()

        self.assert_(ct(timedelta(seconds=1)) == np.timedelta64(1, "s").astype("m8[ns]"))
        self.assert_(ct(timedelta(microseconds=1)) == np.timedelta64(1, "us").astype("m8[ns]"))
        self.assert_(ct(timedelta(days=1)) == np.timedelta64(1, "D").astype("m8[ns]"))
Exemplo n.º 12
0
    def test_short_format_converters(self):
        _skip_if_numpy_not_friendly()

        def conv(v):
            return v.astype("m8[ns]")

        self.assert_(ct("10") == np.timedelta64(10, "ns"))
        self.assert_(ct("10ns") == np.timedelta64(10, "ns"))
        self.assert_(ct("100") == np.timedelta64(100, "ns"))
        self.assert_(ct("100ns") == np.timedelta64(100, "ns"))

        self.assert_(ct("1000") == np.timedelta64(1000, "ns"))
        self.assert_(ct("1000ns") == np.timedelta64(1000, "ns"))
        self.assert_(ct("1000NS") == np.timedelta64(1000, "ns"))

        self.assert_(ct("10us") == np.timedelta64(10000, "ns"))
        self.assert_(ct("100us") == np.timedelta64(100000, "ns"))
        self.assert_(ct("1000us") == np.timedelta64(1000000, "ns"))
        self.assert_(ct("1000Us") == np.timedelta64(1000000, "ns"))
        self.assert_(ct("1000uS") == np.timedelta64(1000000, "ns"))

        self.assert_(ct("1ms") == np.timedelta64(1000000, "ns"))
        self.assert_(ct("10ms") == np.timedelta64(10000000, "ns"))
        self.assert_(ct("100ms") == np.timedelta64(100000000, "ns"))
        self.assert_(ct("1000ms") == np.timedelta64(1000000000, "ns"))

        self.assert_(ct("-1s") == -np.timedelta64(1000000000, "ns"))
        self.assert_(ct("1s") == np.timedelta64(1000000000, "ns"))
        self.assert_(ct("10s") == np.timedelta64(10000000000, "ns"))
        self.assert_(ct("100s") == np.timedelta64(100000000000, "ns"))
        self.assert_(ct("1000s") == np.timedelta64(1000000000000, "ns"))

        self.assert_(ct("1d") == conv(np.timedelta64(1, "D")))
        self.assert_(ct("-1d") == -conv(np.timedelta64(1, "D")))
        self.assert_(ct("1D") == conv(np.timedelta64(1, "D")))
        self.assert_(ct("10D") == conv(np.timedelta64(10, "D")))
        self.assert_(ct("100D") == conv(np.timedelta64(100, "D")))
        self.assert_(ct("1000D") == conv(np.timedelta64(1000, "D")))
        self.assert_(ct("10000D") == conv(np.timedelta64(10000, "D")))

        # space
        self.assert_(ct(" 10000D ") == conv(np.timedelta64(10000, "D")))
        self.assert_(ct(" - 10000D ") == -conv(np.timedelta64(10000, "D")))

        # invalid
        self.assertRaises(ValueError, ct, "1foo")
        self.assertRaises(ValueError, ct, "foo")
Exemplo n.º 13
0
 def test_timedelta_conversions(self):
     self.assertEqual(ct(timedelta(seconds=1)), np.timedelta64(1, "s").astype("m8[ns]"))
     self.assertEqual(ct(timedelta(microseconds=1)), np.timedelta64(1, "us").astype("m8[ns]"))
     self.assertEqual(ct(timedelta(days=1)), np.timedelta64(1, "D").astype("m8[ns]"))
Exemplo n.º 14
0
    def test_short_format_converters(self):
        _skip_if_numpy_not_friendly()

        def conv(v):
            return v.astype('m8[ns]')

        self.assertEqual(ct('10'), np.timedelta64(10,'ns'))
        self.assertEqual(ct('10ns'), np.timedelta64(10,'ns'))
        self.assertEqual(ct('100'), np.timedelta64(100,'ns'))
        self.assertEqual(ct('100ns'), np.timedelta64(100,'ns'))

        self.assertEqual(ct('1000'), np.timedelta64(1000,'ns'))
        self.assertEqual(ct('1000ns'), np.timedelta64(1000,'ns'))
        self.assertEqual(ct('1000NS'), np.timedelta64(1000,'ns'))

        self.assertEqual(ct('10us'), np.timedelta64(10000,'ns'))
        self.assertEqual(ct('100us'), np.timedelta64(100000,'ns'))
        self.assertEqual(ct('1000us'), np.timedelta64(1000000,'ns'))
        self.assertEqual(ct('1000Us'), np.timedelta64(1000000,'ns'))
        self.assertEqual(ct('1000uS'), np.timedelta64(1000000,'ns'))

        self.assertEqual(ct('1ms'), np.timedelta64(1000000,'ns'))
        self.assertEqual(ct('10ms'), np.timedelta64(10000000,'ns'))
        self.assertEqual(ct('100ms'), np.timedelta64(100000000,'ns'))
        self.assertEqual(ct('1000ms'), np.timedelta64(1000000000,'ns'))

        self.assertEqual(ct('-1s'), -np.timedelta64(1000000000,'ns'))
        self.assertEqual(ct('1s'), np.timedelta64(1000000000,'ns'))
        self.assertEqual(ct('10s'), np.timedelta64(10000000000,'ns'))
        self.assertEqual(ct('100s'), np.timedelta64(100000000000,'ns'))
        self.assertEqual(ct('1000s'), np.timedelta64(1000000000000,'ns'))

        self.assertEqual(ct('1d'), conv(np.timedelta64(1,'D')))
        self.assertEqual(ct('-1d'), -conv(np.timedelta64(1,'D')))
        self.assertEqual(ct('1D'), conv(np.timedelta64(1,'D')))
        self.assertEqual(ct('10D'), conv(np.timedelta64(10,'D')))
        self.assertEqual(ct('100D'), conv(np.timedelta64(100,'D')))
        self.assertEqual(ct('1000D'), conv(np.timedelta64(1000,'D')))
        self.assertEqual(ct('10000D'), conv(np.timedelta64(10000,'D')))

        # space
        self.assertEqual(ct(' 10000D '), conv(np.timedelta64(10000,'D')))
        self.assertEqual(ct(' - 10000D '), -conv(np.timedelta64(10000,'D')))

        # invalid
        self.assertRaises(ValueError, ct, '1foo')
        self.assertRaises(ValueError, ct, 'foo')
Exemplo n.º 15
0
    def test_timedelta_conversions(self):
        _skip_if_numpy_not_friendly()

        self.assertEqual(ct(timedelta(seconds=1)), np.timedelta64(1,'s').astype('m8[ns]'))
        self.assertEqual(ct(timedelta(microseconds=1)), np.timedelta64(1,'us').astype('m8[ns]'))
        self.assertEqual(ct(timedelta(days=1)), np.timedelta64(1,'D').astype('m8[ns]'))
Exemplo n.º 16
0
    def test_short_format_converters(self):
        def conv(v):
            return v.astype("m8[ns]")

        self.assertEqual(ct("10"), np.timedelta64(10, "ns"))
        self.assertEqual(ct("10ns"), np.timedelta64(10, "ns"))
        self.assertEqual(ct("100"), np.timedelta64(100, "ns"))
        self.assertEqual(ct("100ns"), np.timedelta64(100, "ns"))

        self.assertEqual(ct("1000"), np.timedelta64(1000, "ns"))
        self.assertEqual(ct("1000ns"), np.timedelta64(1000, "ns"))
        self.assertEqual(ct("1000NS"), np.timedelta64(1000, "ns"))

        self.assertEqual(ct("10us"), np.timedelta64(10000, "ns"))
        self.assertEqual(ct("100us"), np.timedelta64(100000, "ns"))
        self.assertEqual(ct("1000us"), np.timedelta64(1000000, "ns"))
        self.assertEqual(ct("1000Us"), np.timedelta64(1000000, "ns"))
        self.assertEqual(ct("1000uS"), np.timedelta64(1000000, "ns"))

        self.assertEqual(ct("1ms"), np.timedelta64(1000000, "ns"))
        self.assertEqual(ct("10ms"), np.timedelta64(10000000, "ns"))
        self.assertEqual(ct("100ms"), np.timedelta64(100000000, "ns"))
        self.assertEqual(ct("1000ms"), np.timedelta64(1000000000, "ns"))

        self.assertEqual(ct("-1s"), -np.timedelta64(1000000000, "ns"))
        self.assertEqual(ct("1s"), np.timedelta64(1000000000, "ns"))
        self.assertEqual(ct("10s"), np.timedelta64(10000000000, "ns"))
        self.assertEqual(ct("100s"), np.timedelta64(100000000000, "ns"))
        self.assertEqual(ct("1000s"), np.timedelta64(1000000000000, "ns"))

        self.assertEqual(ct("1d"), conv(np.timedelta64(1, "D")))
        self.assertEqual(ct("-1d"), -conv(np.timedelta64(1, "D")))
        self.assertEqual(ct("1D"), conv(np.timedelta64(1, "D")))
        self.assertEqual(ct("10D"), conv(np.timedelta64(10, "D")))
        self.assertEqual(ct("100D"), conv(np.timedelta64(100, "D")))
        self.assertEqual(ct("1000D"), conv(np.timedelta64(1000, "D")))
        self.assertEqual(ct("10000D"), conv(np.timedelta64(10000, "D")))

        # space
        self.assertEqual(ct(" 10000D "), conv(np.timedelta64(10000, "D")))
        self.assertEqual(ct(" - 10000D "), -conv(np.timedelta64(10000, "D")))

        # invalid
        self.assertRaises(ValueError, ct, "1foo")
        self.assertRaises(ValueError, ct, "foo")
Exemplo n.º 17
0
    def test_short_format_converters(self):
        _skip_if_not_numpy17_friendly()

        def conv(v):
            return v.astype('m8[ns]')

        self.assertEqual(ct('10'), np.timedelta64(10, 'ns'))
        self.assertEqual(ct('10ns'), np.timedelta64(10, 'ns'))
        self.assertEqual(ct('100'), np.timedelta64(100, 'ns'))
        self.assertEqual(ct('100ns'), np.timedelta64(100, 'ns'))

        self.assertEqual(ct('1000'), np.timedelta64(1000, 'ns'))
        self.assertEqual(ct('1000ns'), np.timedelta64(1000, 'ns'))
        self.assertEqual(ct('1000NS'), np.timedelta64(1000, 'ns'))

        self.assertEqual(ct('10us'), np.timedelta64(10000, 'ns'))
        self.assertEqual(ct('100us'), np.timedelta64(100000, 'ns'))
        self.assertEqual(ct('1000us'), np.timedelta64(1000000, 'ns'))
        self.assertEqual(ct('1000Us'), np.timedelta64(1000000, 'ns'))
        self.assertEqual(ct('1000uS'), np.timedelta64(1000000, 'ns'))

        self.assertEqual(ct('1ms'), np.timedelta64(1000000, 'ns'))
        self.assertEqual(ct('10ms'), np.timedelta64(10000000, 'ns'))
        self.assertEqual(ct('100ms'), np.timedelta64(100000000, 'ns'))
        self.assertEqual(ct('1000ms'), np.timedelta64(1000000000, 'ns'))

        self.assertEqual(ct('-1s'), -np.timedelta64(1000000000, 'ns'))
        self.assertEqual(ct('1s'), np.timedelta64(1000000000, 'ns'))
        self.assertEqual(ct('10s'), np.timedelta64(10000000000, 'ns'))
        self.assertEqual(ct('100s'), np.timedelta64(100000000000, 'ns'))
        self.assertEqual(ct('1000s'), np.timedelta64(1000000000000, 'ns'))

        self.assertEqual(ct('1d'), conv(np.timedelta64(1, 'D')))
        self.assertEqual(ct('-1d'), -conv(np.timedelta64(1, 'D')))
        self.assertEqual(ct('1D'), conv(np.timedelta64(1, 'D')))
        self.assertEqual(ct('10D'), conv(np.timedelta64(10, 'D')))
        self.assertEqual(ct('100D'), conv(np.timedelta64(100, 'D')))
        self.assertEqual(ct('1000D'), conv(np.timedelta64(1000, 'D')))
        self.assertEqual(ct('10000D'), conv(np.timedelta64(10000, 'D')))

        # space
        self.assertEqual(ct(' 10000D '), conv(np.timedelta64(10000, 'D')))
        self.assertEqual(ct(' - 10000D '), -conv(np.timedelta64(10000, 'D')))

        # invalid
        self.assertRaises(ValueError, ct, '1foo')
        self.assertRaises(ValueError, ct, 'foo')