Exemplo 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])
Exemplo n.º 2
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)
Exemplo n.º 3
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)
            ])
Exemplo n.º 4
0
 def test_index_datetime_binary_operator_b(self) -> None:
     index = IndexDateGO.from_date_range('2018-03-12', '2018-03-14')
     a1 = index + Index((1, 2, 3))
     self.assertEqual(a1.tolist(), [
         datetime.date(2018, 3, 13),
         datetime.date(2018, 3, 15),
         datetime.date(2018, 3, 17)
     ])
    def test_index_datetime_binary_operator_a(self) -> None:
        index = IndexDateGO.from_date_range('2018-03-12', '2018-03-15')
        index.append('2018-03-16')

        self.assertEqual((index + 2).tolist(),
                [datetime.date(2018, 3, 14), datetime.date(2018, 3, 15), datetime.date(2018, 3, 16), datetime.date(2018, 3, 17), datetime.date(2018, 3, 18)])

        with self.assertRaises(NotImplementedError):
            _ = index @ []
Exemplo n.º 6
0
    def test_index_from_pandas_c(self) -> None:
        import pandas

        pdidx = pandas.DatetimeIndex(('2018-01-01', '2018-06-01'), name='foo')
        idx = IndexDateGO.from_pandas(pdidx)
        self.assertFalse(idx.STATIC)
        self.assertEqual(
            idx.values.tolist(),
            [datetime.date(2018, 1, 1),
             datetime.date(2018, 6, 1)])
    def test_index_datetime_append_a(self) -> None:
        index = IndexDateGO.from_date_range('2018-03-12', '2018-03-14')
        with self.assertRaises(KeyError):
            index.append('2018-03-12')

        index.append('2018-03-11')

        self.assertEqual(index.values.tolist(),
                [datetime.date(2018, 3, 12),
                datetime.date(2018, 3, 13),
                datetime.date(2018, 3, 14),
                datetime.date(2018, 3, 11)])
    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)
Exemplo n.º 9
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