Exemplo n.º 1
0
    def test_display_truncate_a(self) -> None:

        config_rows_12_cols_8 = sf.DisplayConfig.from_default(
            display_rows=12, display_columns=8)
        config_rows_7_cols_5 = sf.DisplayConfig.from_default(display_rows=7,
                                                             display_columns=5)

        size = 10000
        columns = 100
        a1 = (np.arange(size * columns)).reshape((size, columns)) * .001
        # insert random nan in very other columns
        for col in range(0, 100, 2):
            a1[:100, col] = np.nan

        index = (hashlib.sha224(str(x).encode('utf-8')).hexdigest()
                 for x in range(size))
        cols = (hashlib.sha224(str(x).encode('utf-8')).hexdigest()
                for x in range(columns))

        f = Frame(a1, index=index, columns=cols)

        self.assertEqual(
            len(tuple(f.display(config_rows_12_cols_8).to_rows())), 15)

        self.assertEqual(len(tuple(f.display(config_rows_7_cols_5).to_rows())),
                         11)
Exemplo n.º 2
0
    def test_display_html_pre_a(self):
        f = Frame(dict(a=(1, 2), b=(1.2, 3.4), c=(False, True)))

        expected = f.display(
            sf.DisplayConfig(display_format='html_pre', type_color=False))

        html = '''<div style="white-space: pre; font-family: monospace">&lt;Frame&gt;
&lt;Index&gt; a       b         c      &lt;&lt;U1&gt;
&lt;Index&gt;
0       1       1.2       False
1       2       3.4       True
&lt;int64&gt; &lt;int64&gt; &lt;float64&gt; &lt;bool&gt;</div>'''

        self.assertEqual(html.strip(), str(expected).strip())
Exemplo n.º 3
0
    def test_display_type_color_a(self):

        f = Frame(dict(a=(1, 2),
                       b=(1.2, 3.4),
                       c=(False, True),
                       d=(object(), []),
                       e=(1j, 3j),
                       f=(np.datetime64('2014'), np.datetime64('2015')),
                       g=(np.datetime64('2014') - np.datetime64('2015'),
                          np.datetime64('2014') - np.datetime64('2015'))),
                  index=tuple('xy'))
        print(f)
        print(f.loc['x'])

        print(f.display(DisplayConfigs.COLOR))
        print(f.loc['x'].display(DisplayConfigs.COLOR))

        f = sf.Frame(
            dict(a=(1, 2, 3, 4), b=(True, False, True, False), c=list('qrst')))
        f = f.set_index_hierarchy(['a', 'b'])
        f = f.reindex_add_level(columns='I')
        f = f.reindex_add_level(columns='J')
        print(f)
Exemplo n.º 4
0
    def test_display_type_color_a(self):

        f = Frame(dict(a=(1, 2),
                       b=(1.2, 3.4),
                       c=(False, True),
                       d=(object(), []),
                       e=(1j, 3j),
                       f=(np.datetime64('2014'), np.datetime64('2015')),
                       g=(np.datetime64('2014') - np.datetime64('2015'),
                          np.datetime64('2014') - np.datetime64('2015'))),
                  index=tuple('xy'))
        print(f)
        print(f.loc['x'])

        print(f.display(DisplayConfigs.COLOR))
        print(f.loc['x'].display(DisplayConfigs.COLOR))

        f = sf.Frame(
            dict(a=(1, 2, 3, 4), b=(True, False, True, False), c=list('qrst')))
        f = f.set_index_hierarchy(['a', 'b'])
        f = f.reindex_add_level(columns='I')
        f = f.reindex_add_level(columns='J')
        print(f)

        # columns = sf.IndexHierarchy.from_product((96361, 96345), (0, 1))
        # index = sf.IndexHierarchy.from_product((32155, 32175), (0, 4))
        # columns = range(4)
        # index = range(4)
        # f = sf.Frame.from_records(
        #     ([y for y in range(x, x + 4)] for x in range(4)),
        #     index=index, columns=columns)

        from itertools import product
        index = (0x2210, 0x2330)
        columns = (0x1, 0xe)
        f = Frame.from_element_loc_items(
            ((x, chr(sum(x))) for x in product(index, columns)),
            index=index,
            columns=columns,
            dtype=str)
        print(f)

        columns = list('abcdefgh')
        index = range(1, 9)

        f = sf.Frame(np.empty((8, 8), dtype='U1'),
                     columns=columns,
                     index=index)
        print(f)

        # f.display(sf.DisplayActive.get(display_format='html_datatables'))

        # f.to_html_datatables()
        columns = tuple('efgh')
        index = range(3, 0, -1)

        f = Frame.from_element_loc_items(
            (
                ((2, 'f'), chr(0x265F)),  # pawn
                ((2, 'g'), chr(0x265F)),
                ((2, 'h'), chr(0x265F)),
                ((1, 'e'), chr(0x265A)),  # king
                ((1, 'h'), chr(0x265C)),  # rook
            ),
            index=index,
            columns=columns,
            dtype=str)

        #part of Sicilian Defense Najdorf Variation
        columns = tuple('hgfe')
        index = range(6, 9)

        f = Frame.from_element_loc_items(
            (
                ((7, 'h'), chr(0x265F)),  # pawn
                ((6, 'g'), chr(0x265F)),
                ((7, 'f'), chr(0x265F)),
                ((7, 'e'), chr(0x265F)),
                ((8, 'e'), chr(0x265A)),  # king
                ((7, 'g'), chr(0x265D)),  # biship
                ((6, 'f'), chr(0x265E)),  # horse
                ((8, 'h'), chr(0x265C)),  # rook
            ),
            index=index,
            columns=columns,
            dtype=str)

        # s = Series(('', chr(0x265C), '', chr(0x265A)), index=tuple('efgh'))

        # s = Series.from_items((('f', chr(0x265C)), ('h', chr(0x265A)))).reindex(tuple('efgh'), fill_value='')

        s = Series.from_items((('f', chr(0x265C)), ('g', chr(0x265A))))

        f.assign.loc[8, :](s, fill_value='')