Пример #1
0
 def test_plus_minus(self):
     # Datetime + Datetime not supported
     with self.assertRaises(TypeError) as cm:
         self.dtvec1 + self.dtvec2
     # Datetime slice -> Datetime
     leading = self.dtvec1[1:]
     trailing = self.dtvec1[:-1]
     self.assertTrue(isinstance(leading, ak.Datetime) and isinstance(trailing, ak.Datetime))
     # Datetime - Datetime -> Timedelta
     diff = leading - trailing
     self.assertTrue(isinstance(diff, ak.Timedelta))
     self.assertTrue((diff == self.onesecond).all())
     # Datetime - DatetimeScalar -> Timedelta
     diff = self.dtvec1 - self.dtscalar
     trange = ak.timedelta_range(start=0, periods=100, freq='s')
     self.assertTrue(isinstance(diff, ak.Timedelta))
     self.assertTrue((diff == trange).all())
     # DatetimeScalar - Datetime -> Timedelta
     diff = self.dtscalar - self.dtvec1
     self.assertTrue(isinstance(diff, ak.Timedelta))
     self.assertTrue((diff == (-trange)).all())
     # Datetime + TimedeltaScalar -> Datetime
     t = (trailing + self.onesecond)
     self.assertTrue(isinstance(t, ak.Datetime))
     self.assertTrue((t == leading).all())
     # TimedeltaScalar + Datetime -> Datetime
     t = (self.onesecond + trailing)
     self.assertTrue(isinstance(t, ak.Datetime))
     self.assertTrue((t == leading).all())
     # Datetime - TimedeltaScalar -> Datetime
     t = leading - self.onesecond
     self.assertTrue(isinstance(t, ak.Datetime))
     self.assertTrue((t == trailing).all())
     # Datetime + Timedelta -> Datetime
     t = (trailing + self.tdvec1[1:])
     self.assertTrue(isinstance(t, ak.Datetime))
     self.assertTrue((t == leading).all())
     # Timedelta + Datetime -> Datetime
     t = (self.tdvec1[1:] + trailing)
     self.assertTrue(isinstance(t, ak.Datetime))
     self.assertTrue((t == leading).all())
     # Datetime - Timedelat -> Datetime
     t = (leading - self.tdvec1[1:])
     self.assertTrue(isinstance(t, ak.Datetime))
     # Timedelta + Timedelta -> Timedelta
     t = self.tdvec1 + self.tdvec1
     self.assertTrue(isinstance(t, ak.Timedelta))
     self.assertTrue((t == ak.Timedelta(2*ak.ones(100, dtype=ak.int64), unit='s')).all())
     # Timedelta + TimedeltaScalar -> Timedelta
     t = self.tdvec1 + self.onesecond
     self.assertTrue(isinstance(t, ak.Timedelta))
     self.assertTrue((t == ak.Timedelta(2*ak.ones(100, dtype=ak.int64), unit='s')).all())
     # Timedelta - Timedelta -> Timedelta
     t = self.tdvec1 - self.tdvec1
     self.assertTrue(isinstance(t, ak.Timedelta))
     self.assertTrue((t == ak.Timedelta(ak.zeros(100, dtype=ak.int64), unit='s')).all())
     # Timedelta - TimedeltaScalar -> Timedelta
     t = self.tdvec1 - self.onesecond
     self.assertTrue(isinstance(t, ak.Timedelta))
     self.assertTrue((t == ak.Timedelta(ak.zeros(100, dtype=ak.int64), unit='s')).all())
Пример #2
0
 def setUp(self):
     ArkoudaTest.setUp(self)
     self.dtvec1 = ak.date_range(start='2021-01-01 12:00:00', periods=100, freq='s')
     self.dtvec2 = ak.Datetime(pd.date_range('2021-01-01 12:00:00', periods=100, freq='s'))
     self.dtscalar = pd.Timestamp('2021-01-01 12:00:00')
     self.tdvec1 = ak.timedelta_range(start='1 second', end='1 second', periods=100)
     self.tdvec2 = ak.Timedelta(ak.ones(100, dtype=ak.int64), unit='s')
     self.onesecond = pd.Timedelta(1, unit='s')