How to use the agate.Table function in agate

To help you get started, we’ve selected a few agate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wireservice / agate / tests / test_table.py View on Github external
def test_print_bars(self):
        table = Table(self.rows, self.column_names, self.column_types)

        output = six.StringIO()
        table.print_bars('three', 'one', output=output)
        lines = output.getvalue().split('\n')  # noqa
github wireservice / agate / tests / test_table.py View on Github external
def test_create_table_no_column_names(self):
        table = Table(self.rows, None, self.column_types)

        self.assertEqual(len(table.rows), 3)
        self.assertEqual(len(table.columns), 3)

        self.assertSequenceEqual(table.columns[0], (1, 2, None))
        self.assertSequenceEqual(table.columns['a'], (1, 2, None))

        with self.assertRaises(KeyError):
            table.columns[None]

        with self.assertRaises(KeyError):
            table.columns['one']

        self.assertSequenceEqual(table.columns[2], ('a', 'b', u'👍'))
        self.assertSequenceEqual(table.columns['c'], ('a', 'b', u'👍'))
github wireservice / agate / tests / test_table / __init__.py View on Github external
def test_where(self):
        table = Table(self.rows, self.column_names, self.column_types)

        new_table = table.where(lambda r: r['one'] in (2, None))

        self.assertIsNot(new_table, table)

        self.assertColumnNames(new_table, self.column_names)
        self.assertColumnTypes(new_table, [Number, Number, Text])
        self.assertRows(new_table, [
            self.rows[1],
            self.rows[2]
        ])
github wireservice / agate / tests / test_table / test_print_bars.py View on Github external
def test_print_bars_mixed_signs(self):
        rows = (
            ('-1.7', 2, 'a'),
            ('11.18', None, None),
            ('0', 1, 'c')
        )

        table = Table(rows, self.column_names, self.column_types)
        table.print_bars('three', 'one')
github wireservice / agate / tests / test_table.py View on Github external
def test_bins_nulls(self):
        rows = []

        for i in range(0, 100):
            rows.append([Decimal(i) / Decimal('100')])

        rows.append([None])

        new_table = Table(rows, self.column_names, self.column_types).bins('number')

        self.assertColumnNames(new_table, ['number', 'Count'])
        self.assertColumnTypes(new_table, [Text, Number])

        self.assertSequenceEqual(new_table.rows[0], ['[0.0 - 0.1)', 10])
        self.assertSequenceEqual(new_table.rows[3], ['[0.3 - 0.4)', 10])
        self.assertSequenceEqual(new_table.rows[9], ['[0.9 - 1.0]', 10])
        self.assertSequenceEqual(new_table.rows[10], [None, 1])
github wireservice / agate / tests / test_table / __init__.py View on Github external
def test_create_table_null_column_names(self):
        column_names = ['one', None, 'three']

        with warnings.catch_warnings():
            warnings.simplefilter('error')

            with self.assertRaises(RuntimeWarning):
                table1 = Table(self.rows, column_types=self.column_types)  # noqa

            with self.assertRaises(RuntimeWarning):
                table2 = Table(self.rows, column_names, self.column_types)  # noqa

        table3 = Table(self.rows, column_names, self.column_types)

        self.assertColumnNames(table3, ['one', 'b', 'three'])
github wireservice / agate / tests / test_tableset / test_aggregate.py View on Github external
def test_aggregate_key_type(self):
        tables = OrderedDict([
            (1, Table(self.table1, self.column_names, self.column_types)),
            (2, Table(self.table2, self.column_names, self.column_types)),
            (3, Table(self.table3, self.column_names, self.column_types))
        ])

        tableset = TableSet(tables.values(), tables.keys(), key_name='test', key_type=self.number_type)

        new_table = tableset.aggregate([
            ('count', Count())
        ])

        self.assertIsInstance(new_table, Table)
        self.assertColumnNames(new_table, ('test', 'count'))
        self.assertColumnTypes(new_table, [Number, Number])
github wireservice / agate / tests / test_table.py View on Github external
def test_bins_mixed_signs(self):
        rows = []

        for i in range(0, -100, -1):
            rows.append([i + 50])

        new_table = Table(rows, self.column_names, self.column_types).bins('number')

        self.assertColumnNames(new_table, ['number', 'Count'])
        self.assertColumnTypes(new_table, [Text, Number])

        self.assertSequenceEqual(new_table.rows[0], ['[-50 - -40)', 9])
        self.assertSequenceEqual(new_table.rows[3], ['[-20 - -10)', 10])
        self.assertSequenceEqual(new_table.rows[9], ['[40 - 50]', 11])
github wireservice / agate / tests / test_table / test_bins.py View on Github external
def test_bins_decimals(self):
        rows = []

        for i in range(0, 100):
            rows.append([Decimal(i) / Decimal('100')])

        new_table = Table(rows, self.column_names, self.column_types).bins('number')

        self.assertColumnNames(new_table, ['number', 'Count'])
        self.assertColumnTypes(new_table, [Text, Number])

        self.assertSequenceEqual(new_table.rows[0], ['[0.0 - 0.1)', 10])
        self.assertSequenceEqual(new_table.rows[3], ['[0.3 - 0.4)', 10])
        self.assertSequenceEqual(new_table.rows[9], ['[0.9 - 1.0]', 10])
github nprapps / graphics-archive / 2015 / 12 / buffalo-refugees-20151123 / data / scripts / parse.py View on Github external
# Not all years are available for every country so default to zero
        origin_row = [ordered.rows[0]['origin'],0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        total_sum = 0

        for row in ordered.rows:
            # Create list of values by year
            year_index = column_names.index(str(row['year']))
            origin_row[year_index] = row['arrivals']
            total_sum += row['arrivals']

        origin_row.append(total_sum)
        rows.append(origin_row)

    # Add a 'total' column header
    column_names.append('total')
    origin_by_year = agate.Table(rows, column_names)
    origin_by_year.to_csv('output/new-origin_by_year-buffalo-2002-2015.csv')