How to use the agate.Text 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-sql / tests / test_agatesql.py View on Github external
def test_back_and_forth(self):
        engine = create_engine(self.connection_string)
        connection = engine.connect()

        self.table.to_sql(connection, 'test')

        table = agate.Table.from_sql(connection, 'test')

        self.assertSequenceEqual(table.column_names, self.column_names)
        self.assertIsInstance(table.column_types[0], agate.Number)
        self.assertIsInstance(table.column_types[1], agate.Text)
        self.assertIsInstance(table.column_types[2], agate.Boolean)
        self.assertIsInstance(table.column_types[3], agate.Date)
        self.assertIsInstance(table.column_types[4], agate.DateTime)

        self.assertEqual(len(table.rows), len(self.table.rows))
        self.assertSequenceEqual(table.rows[0], self.table.rows[0])
github HUJI-Deep / Generative-ConvACs / exp / mnist / dpm / test_iid / summary.py View on Github external
def percentages(column, precision=2):
    return (column, agate.Formula(agate.Text(), lambda r: ('%%.%df' % precision) % (r[column]*100)))
github wireservice / agate-sql / tests / test_agatesql.py View on Github external
def setUp(self):
        self.rows = (
            (1.123, 'a', True, '11/4/2015', '11/4/2015 12:22 PM'),
            (2, u'👍', False, '11/5/2015', '11/4/2015 12:45 PM'),
            (2, u'c', False, '11/5/2015', '11/4/2015 12:45 PM'),
            (None, 'b', None, None, None),
        )

        self.column_names = [
            'number', 'text', 'boolean', 'date', 'datetime',
        ]

        self.column_types = [
            agate.Number(), agate.Text(), agate.Boolean(),
            agate.Date(), agate.DateTime(),
        ]

        self.table = agate.Table(self.rows, self.column_names, self.column_types)
        self.connection_string = 'sqlite:///:memory:'
github polygraph-cool / last-two-minute-report / custom / incorrect-call.py View on Github external
'review_decision': agate.Text(),
    'comment': agate.Text(),
    'video': agate.Text(),
    'game_id': agate.Text(),
    'play_id': agate.Text(),
    'away': agate.Text(),
    'home': agate.Text(),
    'date': agate.Text(),
    'ref_1': agate.Text(),
    'ref_2': agate.Text(),
    'ref_3': agate.Text(),
    'score_away': agate.Number(),
    'score_home': agate.Number(),
    'original_pdf': agate.Text(),
    'box_score_url': agate.Text(),
    'committing_team': agate.Text(),
    'disadvantaged_team': agate.Text()
}

data = agate.Table.from_csv('../.tmp/concat.csv', column_types=specified_types)

select_columns = ['play_id', 'ref_1', 'ref_2', 'ref_3', 'video', 'box_score_url', 'original_pdf', 'game_id']

ic = data.where(lambda r: r['review_decision'] == 'IC').select(select_columns)

ic.to_csv('incorrect_call.csv')
github wireservice / agate-sql / agatesql / table.py View on Github external
for sql_column in sql_table.columns:
        column_names.append(sql_column.name)

        if type(sql_column.type) in INTERVAL_MAP.values():
            py_type = datetime.timedelta
        else:
            py_type = sql_column.type.python_type

        if py_type in [int, float, decimal.Decimal]:
            if py_type is float:
                sql_column.type.asdecimal = True
            column_types.append(agate.Number())
        elif py_type is bool:
            column_types.append(agate.Boolean())
        elif issubclass(py_type, six.string_types):
            column_types.append(agate.Text())
        elif py_type is datetime.date:
            column_types.append(agate.Date())
        elif py_type is datetime.datetime:
            column_types.append(agate.DateTime())
        elif py_type is datetime.timedelta:
            column_types.append(agate.TimeDelta())
        else:
            raise ValueError('Unsupported sqlalchemy column type: %s' % type(sql_column.type))

    s = select([sql_table])

    rows = connection.execute(s)

    try:
        return agate.Table(rows, column_names, column_types)
    finally:
github wireservice / csvkit / csvkit / cli.py View on Github external
def get_column_types(self):
        if getattr(self.args, 'blanks', None):
            type_kwargs = {'null_values': ()}
        else:
            type_kwargs = {}

        text_type = agate.Text(**type_kwargs)

        if self.args.no_inference:
            types = [text_type]
        else:
            number_type = agate.Number(locale=self.args.locale, **type_kwargs)

            # See the order in the `agate.TypeTester` class.
            types = [
                agate.Boolean(**type_kwargs),
                agate.TimeDelta(**type_kwargs),
                agate.Date(date_format=self.args.date_format, **type_kwargs),
                agate.DateTime(datetime_format=self.args.datetime_format, **type_kwargs),
                text_type,
            ]

            # In order to parse dates like "20010101".
github wireservice / agate / example.py View on Github external
#!/usr/bin/env python

import agate

tester = agate.TypeTester(force={
    'fips': agate.Text()
})

table = agate.Table.from_csv('examples/realdata/ks_1033_data.csv', column_types=tester)

# Question 1: What was the total cost to Kansas City area counties?

# Filter to counties containing Kansas City
kansas_city = table.where(lambda r: r['county'] in ('JACKSON', 'CLAY', 'CASS', 'PLATTE'))

# Sum total_cost of four counties
print('Total for Kansas City area: %i' % kansas_city.aggregate(agate.Sum('total_cost')))

# Question 2: Which counties spent the most?

# Group by counties
counties = table.group_by('county')
github polygraph-cool / last-two-minute-report / analysis / explore.py View on Github external
# coding: utf-8

# In[1]:

import agate
import math

specified_types = {
    'period': agate.Text(),
    'time': agate.Text(),
    'seconds_left': agate.Number(),
    'call_type': agate.Text(),
    'committing_player': agate.Text(),
    'disadvantaged_player': agate.Text(),
    'review_decision': agate.Text(),
    'comment': agate.Text(),
    'video': agate.Text(),
    'committing_team': agate.Text(),
    'disadvantaged_team': agate.Text(),
    'game_id': agate.Text(),
    'play_id': agate.Text(),
    'away': agate.Text(),
    'home': agate.Text(),
    'date': agate.Text(),
    'ref_1': agate.Text(),