Beispiel #1
0
    def test_display_float_scientific_a(self) -> None:

        s1 = sf.Series([3.1, 5.2])**40

        self.assertEqual(
            s1.display(sf.DisplayConfig(type_color=False)).to_rows(), [
                '<Series>', '<Index>', '0        4.51302515e+19',
                '1        4.36650282e+28', '<int64>  <float64>'
            ])

        # non default config for scientifici will truncate values
        self.assertEqual(
            s1.display(
                sf.DisplayConfig(
                    type_color=False,
                    value_format_float_scientific='{:f}')).to_rows(), [
                        '<Series>', '<Index>', '0        45130251461102272...',
                        '1        43665028242109266...', '<int64>  <float64>'
                    ])

        self.assertEqual(
            s1.display(
                sf.DisplayConfig(
                    type_color=False,
                    value_format_float_scientific='{:.2e}')).to_rows(), [
                        '<Series>', '<Index>', '0        4.51e+19',
                        '1        4.37e+28', '<int64>  <float64>'
                    ])
Beispiel #2
0
    def test_display_float_scientific_b(self) -> None:

        s1 = sf.Series([3.1j, 5.2j])**40

        self.assertEqual(
            s1.display(sf.DisplayConfig(type_color=False)).to_rows(), [
                '<Series>', '<Index>', '0        4.51e+19+0.00e+00j',
                '1        4.37e+28+0.00e+00j', '<int64>  <complex128>'
            ])

        # non default config for scientifici will truncate values
        self.assertEqual(
            s1.display(
                sf.DisplayConfig(
                    type_color=False,
                    value_format_complex_scientific='{:f}')).to_rows(),
            [
                '<Series>', '<Index>', '0        45130251461102338...',
                '1        43665028242109283...', '<int64>  <complex128>'
            ])

        self.assertEqual(
            s1.display(
                sf.DisplayConfig(
                    type_color=False,
                    value_format_complex_scientific='{:.1e}')).to_rows(), [
                        '<Series>', '<Index>', '0        4.5e+19+0.0e+00j',
                        '1        4.4e+28+0.0e+00j', '<int64>  <complex128>'
                    ])
Beispiel #3
0
    def test_display_html_index_b(self) -> None:
        records = (
            (2, 'a', False),
            (30, 'b', False),
        )
        f = Frame.from_records(records,
                               columns=('p', 'q', 'r'),
                               index=('w', 'x'))
        f = f.set_index_hierarchy(('p', 'q'))

        # this uses cell width normaliz
        post = f.display(
            sf.DisplayConfig(display_format=DisplayFormats.HTML_PRE,
                             cell_max_width_leftmost=20)).to_rows()

        self.assertEqual(
            post[2],
            '<span style="color: #777777">&lt;IndexHierarchy: ...</span>')

        post = f.display(
            sf.DisplayConfig(display_format=DisplayFormats.HTML_PRE,
                             cell_max_width_leftmost=36)).to_rows()

        self.assertEqual(
            post[2],
            '<span style="color: #777777">&lt;IndexHierarchy: (&#x27;p&#x27;, &#x27;q&#x27;)&gt;</span>'
        )
Beispiel #4
0
    def test_display_html_table_a(self) -> None:
        f = sf.Frame.from_dict(
            dict(a=(1, 2, 3, 4), b=(True, False, True, False), c=list('qrst')))
        f = f.set_index_hierarchy(['a', 'b'])
        f = f.relabel_add_level(columns='I')
        f = f.relabel_add_level(columns='J')

        expected1 = f.display(
            sf.DisplayConfig(display_format='html_table', type_color=False))

        html1 = '''<table border="1"><thead><tr><th>&lt;Frame&gt;</th><th></th><th></th><th></th><th></th><th></th></tr><tr><th>&lt;IndexHierarchy&gt;</th><th></th><th>J</th><th>J</th><th>J</th><th>&lt;&lt;U1&gt;</th></tr><tr><th></th><th></th><th>I</th><th>I</th><th>I</th><th>&lt;&lt;U1&gt;</th></tr><tr><th></th><th></th><th>a</th><th>b</th><th>c</th><th>&lt;&lt;U1&gt;</th></tr><tr><th>&lt;IndexHierarchy: (&#x27;a&#x27;, &#x27;b&#x27;)&gt;</th><th></th><th></th><th></th><th></th><th></th></tr></thead><tbody><tr><th>1</th><th>True</th><td>1</td><td>True</td><td>q</td><td></td></tr><tr><th>2</th><th>False</th><td>2</td><td>False</td><td>r</td><td></td></tr><tr><th>3</th><th>True</th><td>3</td><td>True</td><td>s</td><td></td></tr><tr><th>4</th><th>False</th><td>4</td><td>False</td><td>t</td><td></td></tr><tr><th>&lt;int64&gt;</th><th>&lt;bool&gt;</th><td>&lt;int64&gt;</td><td>&lt;bool&gt;</td><td>&lt;&lt;U1&gt;</td><td></td></tr></tbody></table>
        '''
        self.assertEqual(html1.strip(), str(expected1).strip())

        expected2 = f.display(
            sf.DisplayConfig(display_format='html_table',
                             type_color=False,
                             type_show=False))

        html2 = '''<table border="1"><thead><tr><th></th><th></th><th>J</th><th>J</th><th>J</th></tr><tr><th></th><th></th><th>I</th><th>I</th><th>I</th></tr><tr><th></th><th></th><th>a</th><th>b</th><th>c</th></tr></thead><tbody><tr><th>1</th><th>True</th><td>1</td><td>True</td><td>q</td></tr><tr><th>2</th><th>False</th><td>2</td><td>False</td><td>r</td></tr><tr><th>3</th><th>True</th><td>3</td><td>True</td><td>s</td></tr><tr><th>4</th><th>False</th><td>4</td><td>False</td><td>t</td></tr></tbody></table>
        '''
        self.assertEqual(html2.strip(), str(expected2).strip())

        expected3 = f.display(
            sf.DisplayConfig(display_format='html_table',
                             type_color=False,
                             type_show=False,
                             include_index=False))

        html3 = '''<table border="1"><thead><tr><th>J</th><th>J</th><th>J</th></tr><tr><th>I</th><th>I</th><th>I</th></tr><tr><th>a</th><th>b</th><th>c</th></tr></thead><tbody><tr><td>1</td><td>True</td><td>q</td></tr><tr><td>2</td><td>False</td><td>r</td></tr><tr><td>3</td><td>True</td><td>s</td></tr><tr><td>4</td><td>False</td><td>t</td></tr></tbody></table>
        '''
        self.assertEqual(html3.strip(), str(expected3).strip())

        expected4 = f.display(
            sf.DisplayConfig(display_format='html_table',
                             type_color=False,
                             type_show=False,
                             include_columns=False))

        html4 = '''<table border="1"><tbody><tr><th>1</th><th>True</th><td>1</td><td>True</td><td>q</td></tr><tr><th>2</th><th>False</th><td>2</td><td>False</td><td>r</td></tr><tr><th>3</th><th>True</th><td>3</td><td>True</td><td>s</td></tr><tr><th>4</th><th>False</th><td>4</td><td>False</td><td>t</td></tr></tbody></table>
        '''
        self.assertEqual(html4.strip(), str(expected4).strip())

        expected5 = f.display(
            sf.DisplayConfig(display_format='html_table',
                             type_color=False,
                             type_show=False,
                             include_index=False,
                             include_columns=False))

        html5 = '''<table border="1"><tbody><tr><td>1</td><td>True</td><td>q</td></tr><tr><td>2</td><td>False</td><td>r</td></tr><tr><td>3</td><td>True</td><td>s</td></tr><tr><td>4</td><td>False</td><td>t</td></tr></tbody></table>
        '''
        self.assertEqual(html5.strip(), str(expected5).strip())
Beispiel #5
0
def run_test():
    records = []
    for label, fixture in (('None', None), ):
        for cls in (
                MemorySum,
                MemoryThreadSum,
                MemoryForkSum,
                MemorySpawnSum,
                MMapThreadSum,
                MMapForkSum,
                MMapSpawnSum,
        ):
            runner = cls(fixture)
            record = [cls.__name__, cls.NUMBER, label]
            result = timeit.timeit(f'runner()',
                                   globals=locals(),
                                   number=cls.NUMBER)
            record.append(result)
            records.append(record)
            runner.clear()

    f = sf.FrameGO.from_records(records,
                                columns=('name', 'number', 'fixture', 'time'))

    display = f.iter_element_items().apply(get_format())

    config = sf.DisplayConfig(
        cell_max_width_leftmost=np.inf,
        cell_max_width=np.inf,
        type_show=False,
        display_rows=200,
        include_index=False,
    )
    print(display.display(config))
Beispiel #6
0
    def test_display_max_width_a(self) -> None:
        records = (
            (2, 'a', False),
            (30, 'b', False),
        )
        f1 = Frame.from_records(records,
                                columns=('p', 'q', 'r'),
                                index=('w', 'x'))
        f2 = f1.set_index_hierarchy(('p', 'q'))

        post = f2.display(
            sf.DisplayConfig(type_color=False,
                             cell_max_width_leftmost=20)).to_rows()
        self.assertEqual(post[2], '<IndexHierarchy: ...')

        post = f2.display(
            sf.DisplayConfig(type_color=False,
                             cell_max_width_leftmost=30)).to_rows()
        self.assertEqual(post[2], "<IndexHierarchy: ('p', 'q')>")
Beispiel #7
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())
Beispiel #8
0
    def test_display_html_table_a(self) -> None:
        f = sf.Frame.from_dict(
            dict(a=(1, 2, 3, 4), b=(True, False, True, False), c=list('qrst')))
        f = f.set_index_hierarchy(['a', 'b'])
        f = f.relabel_add_level(columns='I')
        f = f.relabel_add_level(columns='J')

        expected = f.display(
            sf.DisplayConfig(display_format='html_table', type_color=False))
        html = '''
<table border="1"><thead><tr><th>&lt;Frame&gt;</th><th></th><th></th><th></th><th></th><th></th></tr><tr><th>&lt;IndexHierarchy&gt;</th><th></th><th>J</th><th>J</th><th>J</th><th>&lt;&lt;U1&gt;</th></tr><tr><th></th><th></th><th>I</th><th>I</th><th>I</th><th>&lt;&lt;U1&gt;</th></tr><tr><th></th><th></th><th>a</th><th>b</th><th>c</th><th>&lt;&lt;U1&gt;</th></tr><tr><th>&lt;IndexHierarchy&gt;</th><th></th><th></th><th></th><th></th><th></th></tr></thead><tbody><tr><th>1</th><th>True</th><td>1</td><td>True</td><td>q</td><td></td></tr><tr><th>2</th><th>False</th><td>2</td><td>False</td><td>r</td><td></td></tr><tr><th>3</th><th>True</th><td>3</td><td>True</td><td>s</td><td></td></tr><tr><th>4</th><th>False</th><td>4</td><td>False</td><td>t</td><td></td></tr><tr><th>&lt;object&gt;</th><th>&lt;object&gt;</th><td>&lt;int64&gt;</td><td>&lt;bool&gt;</td><td>&lt;&lt;U1&gt;</td><td></td></tr></tbody></table>
        '''

        self.assertEqual(html.strip(), str(expected).strip())
def grammar(context):
    from frame_fixtures.core import GrammarDoc
    import static_frame as sf  #type: ignore

    config = sf.DisplayConfig(include_index=False,
                              type_show=False,
                              cell_max_width=40)
    # container components
    cc = GrammarDoc.container_components()
    print(cc.to_rst(config))

    # container types
    cc = GrammarDoc.specifiers_constructor()
    print(cc.to_rst(config))

    # container types
    cc = GrammarDoc.specifiers_dtype()
    print(cc.to_rst(config))
Beispiel #10
0
def run_test():
    records = []
    for cls in (
            DirectFromString,
            ParseFromString,
            ShiftDay,
            DeriveYear,
            TrueOnMonday,
            TrueOnEOM,
            TrueLessThan,
            ConvertToStr,
            ):
        runner = cls()
        record = [cls.__name__, cls.NUMBER]
        for func_name in ('dt', 'dt64'):
            result = timeit.timeit(
                    f'runner.{func_name}()',
                    globals=locals(),
                    number=cls.NUMBER)
            record.append(result)
        records.append(record)

    f = sf.FrameGO.from_records(records,
            columns=('name', 'number', 'dt', 'dt64')
            )

    f['dt64/dt'] = f['dt64'] / f['dt']
    f['dt/dt64'] = f['dt'] / f['dt64']

    f['dt64-faster'] = f['dt/dt64'] > 1

    display = f.iter_element_items().apply(get_format())

    config = sf.DisplayConfig(
            cell_max_width_leftmost=np.inf,
            cell_max_width=np.inf,
            type_show=False,
            display_rows=200,
            include_index=False,
            )
    print(display.display(config))
def run_test():
    records = []
    for label, fixture in (
        ('wide', FF_wide),
        ('tall', FF_tall),
        ('square', FF_square),
    ):
        # for label, fixture in (('square', FF_square),):
        fixtures = [fixture] * 100
        for cls in (
                FileWriteBusParquet,
                FileWriteBusNPZ,
                # FileWritePickle,
                FileReadBusParquet,
                FileReadBusNPZ,
                # FileReadPickle,
        ):
            runner = cls(fixtures)
            record = [cls.__name__, cls.NUMBER, label]
            result = timeit.timeit(f'runner()',
                                   globals=locals(),
                                   number=cls.NUMBER)
            record.append(result)
            records.append(record)

    f = sf.FrameGO.from_records(records,
                                columns=('name', 'number', 'fixture', 'time'))

    display = f.iter_element_items().apply(get_format())

    config = sf.DisplayConfig(
        cell_max_width_leftmost=np.inf,
        cell_max_width=np.inf,
        type_show=False,
        display_rows=200,
        include_index=False,
    )
    print(display.display(config))
Beispiel #12
0
                ThreadPool,
                # ProcessPool,
        ):
            runner = cls(size, groups)
            record = [cls.__name__, cls.NUMBER, size, groups]
            result = timeit.timeit(f'runner.run()',
                                   globals=locals(),
                                   number=cls.NUMBER)
            record.append(result)
            records.append(record)

    f = sf.FrameGO.from_records(records,
                                columns=('name', 'number', 'size', 'groups',
                                         'time'))

    display = f.iter_element_items().apply(get_format())

    config = sf.DisplayConfig(
        cell_max_width_leftmost=np.inf,
        cell_max_width=np.inf,
        type_show=False,
        display_rows=200,
        include_index=False,
    )
    print(display.display(config))
    # import ipdb; ipdb.set_trace()


if __name__ == '__main__':
    run_test()
Beispiel #13
0
def run_test():
    records = []
    for dtype_hetero, fixture_label, fixture in (
            fixture_to_pair('uniform', FF_wide_uniform),
            fixture_to_pair('mixed', FF_wide_mixed),
            fixture_to_pair('columnar', FF_wide_columnar),
            fixture_to_pair('uniform', FF_tall_uniform),
            fixture_to_pair('mixed', FF_tall_mixed),
            fixture_to_pair('columnar', FF_tall_columnar),
            fixture_to_pair('uniform', FF_square_uniform),
            fixture_to_pair('mixed', FF_square_mixed),
            fixture_to_pair('columnar', FF_square_columnar),
    ):
        cls_read = (
            PDReadParquetArrow,
            PDReadParquetArrowNoComp,
            # PDReadParquetFast, # not faster!
            PDReadFeather,

            # SFReadParquet,
            SFReadNPZ,
            SFReadNPY,
            SFReadPickle,
            # SFReadNPYMM,
        )
        cls_write = (
            PDWriteParquetArrow,
            PDWriteParquetArrowNoComp,
            # PDWriteParquetFast, # not faster!
            # SFWriteParquet,
            PDWriteFeather,
            SFWriteNPZ,
            SFWriteNPY,
            SFWritePickle,
        )

        for cls, category_prefix in chain(
                zip(cls_read, repeat('read')),
                zip(cls_write, repeat('write')),
        ):
            runner = cls(fixture)
            category = f'{category_prefix} {dtype_hetero}'

            record = [cls.__name__, cls.NUMBER, category, fixture_label]
            try:
                result = timeit.timeit(f'runner()',
                                       globals=locals(),
                                       number=cls.NUMBER)
            except OSError:
                result = np.nan
            finally:
                runner.clear()
            record.append(result)
            records.append(record)

    f = sf.FrameGO.from_records(records,
                                columns=('name', 'number', 'category',
                                         'fixture', 'time'))

    display = f.iter_element_items().apply(get_format())

    config = sf.DisplayConfig(
        cell_max_width_leftmost=np.inf,
        cell_max_width=np.inf,
        type_show=False,
        display_rows=200,
        include_index=False,
    )
    print(display.display(config))

    plot(f)
Beispiel #14
0
def tables() -> None:
    name = 'Higher-Order Containers'
    columns = ('Bus', 'Batch', 'Quilt', 'Yarn')
    records_items = (
        ('Presented Dimensions', (
            1,
            2,
            2,
            1,
        )),
        ('Approximate Interface', (
            'Series',
            'Frame',
            'Frame',
            'Series',
        )),
        ('Composes', (
            'n Frame',
            '',
            '1 Bus or Yarn of n Frame',
            'm Bus of n Frame',
        )),
        ('Presented shape', (
            '(n,)',
            '',
            '(xn, y) or (x, yn)',
            '(mn,)',
        )),
    )

    f = sf.Frame.from_records_items(records_items, columns=columns, name=name)
    # print(f)
    config = sf.DisplayConfig(cell_max_width=200, type_show=False)
    print(f.name)
    print(f.to_rst(config=config))

    name = 'Constructors & Exporters'
    columns = ('Constructor', 'Exporter')  #type: ignore
    records = (
        ('from_hdf5', 'to_hdf5'),
        ('from_sqlite', 'to_sqlite'),
        (
            'from_zip_csv',
            'to_zip_csv',
        ),
        (
            'from_zip_npz',
            'to_zip_npz',
        ),
        (
            'from_zip_pickle',
            'to_zip_pickle',
        ),
        (
            'from_zip_parquet',
            'to_zip_parquet',
        ),
        (
            'from_zip_tsv',
            'to_zip_tsv',
        ),
        ('from_xlsx', 'to_xlsx'),
    )

    f = sf.Frame.from_records(records, columns=columns, name=name)
    # print(f)
    print(f.name)
    print(f.to_rst(sf.DisplayConfig(include_index=False, type_show=False)))