예제 #1
0
def test_read_with_row_filter(df_type, backend: PostgresBackend, filter_expr,
                              expected_data):
    """Is the full dataset correctly read?"""
    reset_test_table(True)
    if df_type == pd.DataFrame:
        df = backend.read_to_pandas("testdb", row_filter=filter_expr)
    elif df_type == dict:
        df = backend.read_to_dict("testdb", row_filter=filter_expr)
    expected_data.assert_correct_and_equal(df)
예제 #2
0
def test_read_to_pandas_drop_duplicates(backend: PostgresBackend):
    """Is the full dataset correctly read?"""
    reset_test_table(True)
    df = backend.read_to_pandas("testdb", drop_duplicates=True)
    sample_data = SampleDataSet()
    sample_data.first_rows(len(sample_data) - 1).assert_correct_and_equal(df)
예제 #3
0
def test_read_to_pandas_sample_4(backend: PostgresBackend):
    """Is the full dataset correctly read?"""
    reset_test_table(True)
    df = backend.read_to_pandas("testdb", sample=4)
    SampleDataSchema.validate(df)
    assert len(df) == 4
예제 #4
0
def test_read_to_pandas_top_3(backend: PostgresBackend):
    """Is the full dataset correctly read?"""
    reset_test_table(True)
    df = backend.read_to_pandas("testdb", limit=3)
    SampleDataSet().first_rows(3).assert_correct_and_equal(df)
예제 #5
0
def test_read_columns(df_type, backend: PostgresBackend):
    """Is the full dataset correctly read?"""
    reset_test_table(True)
    df = backend.read_to_pandas("testdb", columns=["col_int", "col_string"])
    SampleDataSet().select_columns(
        columns=["col_int", "col_string"]).assert_correct_and_equal(df)
예제 #6
0
def test_read_to_pandas_empty_table(backend: PostgresBackend):
    """Try reading an empty table and see if the column names are fetched"""
    df = backend.read_to_pandas("empty")
    pd.testing.assert_frame_equal(df, pd.DataFrame(columns=["col1", "col2"]))
예제 #7
0
def test_read_to_pandas_argchecks(backend: PostgresBackend, kwargs, exception):
    """Challenge the argument validation of the constructor"""
    with pytest.raises(exception):
        backend.read_to_pandas(**kwargs)