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])
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']]))
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
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'])
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)
def test_compatible_data(df): specs = DataSpecs( col_obs='obs', col_obs_se='obs_se', col_groups=['group'] ) specs._validate_df(df)