Exemplo n.º 1
0
def test_add_dataframe():
    frame = pandas.DataFrame({
        datetime.utcnow(): {
            "id": 1, "name": "foo", "kind": "fizzer", "units": 10},
        datetime.utcnow(): {
            "id": 2, "name": "goo", "kind": "buzzer", "units": 11},
        datetime.utcnow(): {
            "id": 3, "name": "hoo", "kind": "bopper", "units": 12},
        datetime.utcnow(): {
            "id": 4, "name": "ioo", "kind": "fopper", "units": pandas.np.nan}
    }).T
    frame.index.name = "timestamp"

    engine = redpanda.create_engine("sqlite://", convert_unicode=True)
    Widget.metadata.create_all(engine)
    session = redpanda.orm.sessionmaker(bind=engine)()
    session.add_dataframe(Widget, frame, parse_index=True)
    session.commit()

    returned = session.query(Widget).frame()
    cols = sorted(returned.columns | frame.columns)
    assert_frame_equal(returned[cols], frame[cols], check_dtype=False)
Exemplo n.º 2
0
def test_add_dataframe():
    frame = pandas.DataFrame({
        datetime.utcnow(): {
            'id': 1,
            'name': 'foo',
            'kind': 'fizzer',
            'units': 10
        },
        datetime.utcnow(): {
            'id': 2,
            'name': 'goo',
            'kind': 'buzzer',
            'units': 11
        },
        datetime.utcnow(): {
            'id': 3,
            'name': 'hoo',
            'kind': 'bopper',
            'units': 12
        },
        datetime.utcnow(): {
            'id': 4,
            'name': 'ioo',
            'kind': 'fopper',
            'units': numpy.nan
        }
    }).T
    frame.index.name = 'timestamp'

    engine = redpanda.create_engine('sqlite://')
    Widget.metadata.create_all(engine)
    session = redpanda.orm.sessionmaker(bind=engine)()
    session.add_dataframe(Widget, frame, parse_index=True)
    session.commit()

    returned = session.query(Widget).frame()
    cols = sorted(returned.columns | frame.columns)
    assert_frame_equal(returned[cols], frame[cols], check_dtype=False)
Exemplo n.º 3
0
""" Test for mixins module. """


from datetime import datetime
from copy import copy

import mock
import pandas
import redpanda
import sqlalchemy
from pandas.util.testing import assert_frame_equal
from pytest import raises
from redpanda.example import Widget, create_widgets


ENGINE = redpanda.create_engine("sqlite://")
SESSION = redpanda.orm.sessionmaker(bind=ENGINE)()


class NoReadSql(redpanda.example.Base):
    """ Declare an example model. """
    id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
    __tablename__ = "no_read_sql"


class HasColumns(redpanda.example.Base):
    """ Declare an example model. """
    id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
    name = sqlalchemy.Column(sqlalchemy.String)
    fizz = sqlalchemy.Column(sqlalchemy.Integer)
    buzz = sqlalchemy.Column(sqlalchemy.TIMESTAMP)
Exemplo n.º 4
0
""" Test for mixins module. """
from datetime import datetime
from copy import copy
from unittest import mock

import numpy
import pandas
import redpanda
import sqlalchemy
from pandas.testing import assert_frame_equal
from pytest import raises
from redpanda.example import Widget, create_widgets

ENGINE = redpanda.create_engine('sqlite://')
SESSION = redpanda.orm.sessionmaker(bind=ENGINE)()


class NoReadSql(redpanda.example.Base):
    """ Declare an example model. """
    id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
    __tablename__ = 'no_read_sql'


class HasColumns(redpanda.example.Base):
    """ Declare an example model. """
    id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
    name = sqlalchemy.Column(sqlalchemy.String)
    fizz = sqlalchemy.Column(sqlalchemy.Integer)
    buzz = sqlalchemy.Column(sqlalchemy.TIMESTAMP)
    __tablename__ = 'has_columns'
    __read_sql__ = {'columns': ['name', 'fizz', 'buzz']}