Ejemplo n.º 1
0
    def test_index_via_dt_b(self) -> None:

        idx1 = IndexDateGO(('2020-01-01', '2021-02-05', '2019-03-17'))
        idx1.append('2020-04-01')
        idx1.append('2020-05-01')

        self.assertEqual(idx1.via_dt.weekday().tolist(), [2, 4, 6, 2, 4])
Ejemplo n.º 2
0
    def test_index_many_concat_e(self) -> None:

        idx1 = IndexDateGO(('2020-01-01', '2020-01-02'))
        idx2 = IndexDateGO(('2020-02-01', '2020-02-02'))

        post1 = index_many_concat((idx1, idx2), cls_default=Index)

        self.assertEqual(post1.__class__, IndexDate)
        self.assertEqual(
            post1.values.tolist(),  #type: ignore
            [
                datetime.date(2020, 1, 1),
                datetime.date(2020, 1, 2),
                datetime.date(2020, 2, 1),
                datetime.date(2020, 2, 2)
            ])
Ejemplo n.º 3
0
    def test_index_datetime_astype_b(self) -> None:

        idx1 = IndexDateGO(('2020-01-01', '2022-05-10'))

        self.assertEqual(
            idx1.astype('datetime64[ns]').__class__, IndexNanosecondGO)
        self.assertEqual(idx1.astype('datetime64[Y]').__class__, IndexYearGO)
        self.assertEqual(idx1.astype(str).__class__, IndexGO)
Ejemplo n.º 4
0
    def test_index_level_extend_c(self) -> None:
        observations0 = IndexGO(('x', 'y'))
        targets0 = ArrayGO(
                (IndexLevelGO(index=observations0),
                IndexLevelGO(observations0, offset=2)))
        level0 = IndexLevelGO(index=IndexDateGO(('2021', '2022')), targets=targets0)

        observations1 = IndexGO(('x', 'y'))
        targets1 = ArrayGO(
                (IndexLevelGO(index=observations1),
                IndexLevelGO(observations1, offset=2)))
        level1 = IndexLevelGO(index=IndexYearMonthGO(('1853-03', '1873-12')), targets=targets1)
        # RuntimeError: level for extension does not have corresponding types: <class 'static_frame.core.index_datetime.IndexDateGO'>, <class 'static_frame.core.index_datetime.IndexYearMonthGO'>
        with self.assertRaises(RuntimeError):
            level0.extend(level1)
Ejemplo n.º 5
0
    def test_index_datetime_init_a(self) -> None:

        dates = [
            datetime.date(*x) for x in product((2017, ), (
                4,
                5,
            ), range(1, 4))
        ]
        s1 = Series(range(len(dates)), index=IndexDate(dates))

        with self.assertRaises(ErrorInitIndex):
            index = IndexYearMonth(s1.index)

        with self.assertRaises(ErrorInitIndex):
            index = IndexYear(s1.index)  #type: ignore

        # can reuse the map if going from dt64 index to normal index
        # idx2 = Index(s1.index)
        # self.assertTrue(id(idx2._map) == id(s1.index._map)) #type: ignore

        idx3 = IndexDate(s1.index)
        self.assertTrue(id(idx3._map) == id(s1.index._map))  #type: ignore

        with self.assertRaises(ErrorInitIndex):
            index = IndexYear(idx3)  #type: ignore

        # from a date to a finer resolution has to create a new map
        idx4 = IndexMinute(idx3)
        self.assertTrue(id(idx4._map) != id(s1.index._map))  #type: ignore

        # a GO has to create a new map
        idx5 = IndexDateGO(s1.index)
        self.assertTrue(id(idx4._map) != id(s1.index._map))  #type: ignore

        # supplying a dtype to coerce the labels
        with self.assertRaises(ErrorInitIndex):
            idx6 = Index(s1.index, dtype='datetime64[Y]')

        with self.assertRaises(ErrorInitIndex):
            idx7 = Index(s1.index.values.astype('datetime64[Y]'))

        # final resolution from a normal index
        idx8 = IndexMinute(s1.index)
        self.assertTrue(id(idx8._map) != id(s1.index._map))  #type: ignore