def test_index_second_a(self) -> None: # integer arguments are interpreted as seconds from the epoch idx = IndexSecond(range(10)) self.assertAlmostEqualValues(idx.loc['1970-01-01T00:00:07':].values, # type: ignore # https://github.com/python/typeshed/pull/3024 np.array(['1970-01-01T00:00:07', '1970-01-01T00:00:08', '1970-01-01T00:00:09'], dtype='datetime64[s]') )
def test_index_second_a(self): # integer arguments are interpreted as seconds from the epoch idx = IndexSecond(range(10)) self.assertAlmostEqualValues( idx.loc['1970-01-01T00:00:07':].values, np.array([ '1970-01-01T00:00:07', '1970-01-01T00:00:08', '1970-01-01T00:00:09' ], dtype='datetime64[s]'))
def test_index_from_optional_constructor_a(self) -> None: idx1 = index_from_optional_constructor([1, 3, 4], default_constructor=Index) self.assertEqual(idx1.__class__, Index) # given a mutable index and an immutable default, get immutable version idx2 = index_from_optional_constructor(IndexGO((1, 3, 4)), default_constructor=Index) self.assertEqual(idx2.__class__, Index) # given a mutable index and an immutable default, get immutable version idx3 = index_from_optional_constructor(IndexGO((1, 3, 4)), default_constructor=IndexGO) self.assertEqual(idx3.__class__, IndexGO) # given a mutable index and an immutable default, get immutable version idx4 = index_from_optional_constructor(IndexSecond((1, 3, 4)), default_constructor=Index) self.assertEqual(idx4.__class__, IndexSecond)
def test_index_millisecond_frame_a(self) -> None: msg = '''2016-04-28 04:22:12.226 2016-04-28 16:29:21.32 2016-04-28 17:36:13.733 2016-04-30 20:21:07.848 2016-05-01 00:00:33.483 2016-05-01 03:02:03.584 2016-05-01 09:26:43.185 2016-05-01 13:45:22.576 2016-05-01 15:25:46.15''' f = Frame.from_records((x, y) for x, y in enumerate(msg.split('\n'))) idx1 = IndexMillisecond(f[1]) self.assertAlmostEqualValues( idx1.values, np.array([ '2016-04-28T04:22:12.226', '2016-04-28T16:29:21.320', '2016-04-28T17:36:13.733', '2016-04-30T20:21:07.848', '2016-05-01T00:00:33.483', '2016-05-01T03:02:03.584', '2016-05-01T09:26:43.185', '2016-05-01T13:45:22.576', '2016-05-01T15:25:46.150' ], dtype='datetime64[ms]')) idx2 = IndexSecond(f[1]) self.assertAlmostEqualValues( idx2.values, np.array([ '2016-04-28T04:22:12', '2016-04-28T16:29:21', '2016-04-28T17:36:13', '2016-04-30T20:21:07', '2016-05-01T00:00:33', '2016-05-01T03:02:03', '2016-05-01T09:26:43', '2016-05-01T13:45:22', '2016-05-01T15:25:46' ], dtype='datetime64[s]')) f2 = f.set_index(1, index_constructor=IndexMillisecond) self.assertEqual(f2.loc['2016-05', 0].values.tolist(), [4, 5, 6, 7, 8])