Пример #1
0
def test_compatible_specs():
    specs1 = DataSpecs(
        col_obs='obs', col_obs_se='obs_se', col_groups=['group']
    )
    specs2 = DataSpecs(
        col_obs='obs', col_obs_se='obs_se_1', col_groups=['group']
    )
    specs3 = DataSpecsSubclass(
        col_obs='obs', col_obs_se='obs_se',
        col_groups=['group'], col_pop='population'
    )
    _check_compatible_specs([specs1, specs2])
    with pytest.raises(DataSpecCompatibilityError):
        _check_compatible_specs([specs1, specs3])
Пример #2
0
def test_process_data(df):

    d = Data()
    specs = DataSpecs(col_obs='observations',
                      col_obs_se='obs_std_err',
                      col_groups=['group'])
    d.set_data_specs(specs)
    d.process_data(df)
    np.testing.assert_array_equal(d.data['obs'],
                                  np.asarray(df['observations']))
    np.testing.assert_array_equal(d.data['obs_se'],
                                  np.asarray(df['obs_std_err']))
    np.testing.assert_array_equal(d.data['groups'], np.asarray(df[['group']]))
Пример #3
0
def test_attach_detach_specs():

    d = Data()
    assert isinstance(d._data_specs, list)
    assert len(d._data_specs) == 0

    specs = DataSpecs(col_obs='observations',
                      col_obs_se='obs_std_err',
                      col_groups=['group'])

    d.set_data_specs(specs)
    assert specs == d._data_specs[0]

    d.detach_data_specs()
    assert len(d._data_specs) == 0
Пример #4
0
def test_col_attributes():
    specs = DataSpecs(
        col_obs='obs', col_obs_se='obs_se', col_groups=['group']
    )
    assert sorted(specs._col_attributes) == sorted(['col_obs', 'col_obs_se', 'col_groups'])
Пример #5
0
def test_incompatible_data(df):
    with pytest.raises(DataSpecCompatibilityError):
        specs = DataSpecs(
            col_obs='obs', col_obs_se='obs_standard_error', col_groups=['group']
        )
        specs._validate_df(df)
Пример #6
0
def test_compatible_data(df):
    specs = DataSpecs(
        col_obs='obs', col_obs_se='obs_se', col_groups=['group']
    )
    specs._validate_df(df)