Пример #1
0
    def test_display_display_rows_a(self) -> None:

        config_rows_12 = sf.DisplayConfig.from_default(display_rows=12,
                                                       type_color=False)
        config_rows_7 = sf.DisplayConfig.from_default(display_rows=7,
                                                      type_color=False)

        index = list(''.join(x)
                     for x in combinations(string.ascii_lowercase, 2))
        s = Series(range(len(index)), index=index, dtype=np.int64)

        # import ipdb; ipdb.set_trace()
        self.assertEqual(
            s.display(config_rows_12).to_rows(), [
                '<Series>', '<Index>', 'ab       0', 'ac       1',
                'ad       2', 'ae       3', 'af       4', '...      ...',
                'wy       320', 'wz       321', 'xy       322', 'xz       323',
                'yz       324', '<<U2>    <int64>'
            ])

        self.assertEqual(
            s.display(config_rows_7).to_rows(), [
                '<Series>', '<Index>', 'ab       0', 'ac       1',
                'ad       2', '...      ...', 'xy       322', 'xz       323',
                'yz       324', '<<U2>    <int64>'
            ])
Пример #2
0
    def test_display_cell_fill_width_a(self) -> None:

        config_width_12 = sf.DisplayConfig.from_default(
            cell_max_width=12, cell_max_width_leftmost=12, type_color=False)
        config_width_6 = sf.DisplayConfig.from_default(
            cell_max_width=6, cell_max_width_leftmost=6, type_color=False)

        def chunks(size: int, count: int) -> tp.Iterator[str]:
            pos = 0
            for _ in range(count):
                yield LONG_SAMPLE_STR[pos:pos + size]
                pos = pos + size

        s = Series(chunks(20, 3), index=('a', 'b', 'c'))

        self.assertEqual(
            s.display(config=config_width_12).to_rows(), [
                '<Series>', '<Index>', 'a        Lorem ips...',
                'b        t amet, c...', 'c        adipiscin...',
                '<<U1>    <<U20>'
            ])

        self.assertEqual(
            s.display(config=config_width_6).to_rows(), [
                '<Se...', '<In...', 'a      Lor...', 'b      t a...',
                'c      adi...', '<<U1>  <<U20>'
            ])

        config = sf.DisplayConfig.from_default(type_color=False,
                                               cell_max_width_leftmost=20)

        row_count = 2
        index = [str(chr(x)) for x in range(97, 97 + row_count)]
        f = FrameGO(index=index)

        for i in range(4):
            chunker = iter(chunks(10, row_count))
            s = Series((x for x in chunker), index=index)
            f[i] = s

        f.columns._update_array_cache()

        self.assertEqual(
            f.display(config=config).to_rows(), [
                '<FrameGO>',
                '<IndexGO> 0          1          2          3          <int64>',
                '<Index>',
                'a         Lorem ipsu Lorem ipsu Lorem ipsu Lorem ipsu',
                'b         m dolor si m dolor si m dolor si m dolor si',
                '<<U1>     <<U10>     <<U10>     <<U10>     <<U10>'
            ])

        self.assertEqual(
            f.display(config=config_width_6).to_rows(), [
                '<Fr...', '<In... 0      1      2      3      <in...',
                '<In...', 'a      Lor... Lor... Lor... Lor...',
                'b      m d... m d... m d... m d...',
                '<<U1>  <<U10> <<U10> <<U10> <<U10>'
            ])
Пример #3
0
    def test_series_disply_a(self):

        s1 = Series((2, 3), index=list('ab'), name='alt')

        match = tuple(s1.display(DisplayConfig(type_color=False)))
        self.assertEqual(match, (['<Series: alt>'], ['<Index>', ''],
                                 ['a', '2'], ['b', '3'], ['<<U1>', '<int64>']))

        s2 = Series(('a', 'b'),
                    index=Index(('x', 'y'), name='bar'),
                    name='foo')

        match = tuple(s2.display(DisplayConfig(type_color=False)))

        self.assertEqual(match, (['<Series: foo>'], ['<Index: bar>', ''],
                                 ['x', 'a'], ['y', 'b'], ['<<U1>', '<<U1>']))
Пример #4
0
    def test_display_cell_align_left_b(self) -> None:
        config_right = sf.DisplayConfig.from_default(cell_align_left=False,
                                                     type_color=False)
        config_left = sf.DisplayConfig.from_default(cell_align_left=True,
                                                    type_color=False)

        s = Series(range(3), index=('a', 'b', 'c'), dtype=np.int64)

        self.assertEqual(
            s.display(config_right).to_rows(), [
                '<Series>', ' <Index>', '       a       0', '       b       1',
                '       c       2', '   <<U1> <int64>'
            ])

        self.assertEqual(
            s.display(config_left).to_rows(), [
                '<Series>', '<Index>', 'a        0', 'b        1',
                'c        2', '<<U1>    <int64>'
            ])

        records = (
            (2, 2, 'a', False, False),
            (30, 34, 'b', True, False),
            (2, 95, 'c', False, False),
        )

        f1 = Frame.from_records(records,
                                columns=('p', 'q', 'r', 's', 't'),
                                index=('w', 'x', 'y'))

        self.assertEqual(
            f1.display(config_left).to_rows(), [
                '<Frame>', '<Index> p       q       r     s      t      <<U1>',
                '<Index>', 'w       2       2       a     False  False',
                'x       30      34      b     True   False',
                'y       2       95      c     False  False',
                '<<U1>   <int64> <int64> <<U1> <bool> <bool>'
            ])

        self.assertEqual(
            f1.display(config_right).to_rows(), [
                '<Frame>', '<Index>       p       q     r      s      t <<U1>',
                '<Index>', '      w       2       2     a  False  False',
                '      x      30      34     b   True  False',
                '      y       2      95     c  False  False',
                '  <<U1> <int64> <int64> <<U1> <bool> <bool>'
            ])
Пример #5
0
    def test_hierarchy_display_a(self):
        OD = OrderedDict
        tree = OD([
            ('I', OD([('A', (1, 2)), ('B', (1, 2))])),
            ('II', OD([('A', (1, 2)), ('B', (1, 2))])),
        ])

        ih = IndexHierarchy.from_tree(tree)

        post = ih.display()
        self.assertEqual(len(post), 10)

        s = Series(range(8), index=ih)
        post = s.display()
        self.assertEqual(len(post), 11)