def stack(dataset): meta, data = dataset _stack = qp.Stack(NAME_PROJ, add_data={DATA_KEY: {'meta': meta, 'data': data.copy().head(250)}}) yield _stack del _stack
def test_sig_diff_details(self): dataset = self._get_dataset() x = 'q5_3' y = 'gender' sig_level = 0.05 # here we use sig diff with the default parameters, which mimic Dimensions with_sigdiff = dataset.crosstab(x, y, ci=['counts', 'c%'], sig_level=sig_level) # TODO: we can add expected sig-diffs here assert with_sigdiff.shape == (22, 2) # here we can test the sig-diff with different parameters stack = qp.Stack( name='sig', add_data={'sig': { 'meta': dataset.meta(), 'data': dataset.data() }}) stack.add_link(data_keys=['sig'], x=x, y=y, views=['c%', 'counts']) link = stack['sig']['no_filter'][x][y] test = qp.Test(link, 'x|f|:|||counts') # possible parameters are here: #https://github.com/Quantipy/quantipy3/blob/master/quantipy/core/quantify/engine.py#L1783 test = test.set_params(level=sig_level) df = test.run() # assert that we only have 1 significanctly higher value assert df[('gender', 2)].isna().sum() == 7 assert df[('gender', 1)].isna().sum() == 6
def stack(dataset): meta, data = dataset data.loc[30:, 'q5_2'] = np.NaN data.loc[30:, 'q5_4'] = np.NaN store = {DATA_KEY: {'meta': meta, 'data': data.copy()}} _stack = qp.Stack(NAME_PROJ, add_data=store) yield _stack del _stack
def test_vm_p_b_w_both(self): path_stack = './tests/stack_vm.stack' stack = qp.Stack('viewmanager').load(path_stack, load_cache=True) vm = ViewManager(stack, basics=True, nets=False, stats=None, tests=None) vm_views = vm.get_views(cell_items='p', weights='weight_a', bases='both').group().views self.assertEqual(vm_views, E['p_b_w_both']) path_cache = './tests/stack_vm.cache' os.remove(path_stack) os.remove(path_cache)
def stack(request, dataset): meta, data = dataset obj = qp.Stack(NAME_PROJ, add_data={'#': {'meta': meta, 'data': data}}) @request.addfinalizer def teardown(): obj.pop('#') return obj
def test_vm_p_b(self): path_stack = './tests/stack_vm.stack' stack = qp.Stack('viewmanager').load(path_stack, load_cache=True) vm = ViewManager(stack) vm.get_views(cell_items='colpct', freqs=True, nets=False, stats=None, tests=None, weight=None, bases='auto') vm.set_bases('uw', 'uw', False, ['gross', 'base']) vm_views = vm.views self.assertEqual(vm_views, E['p_b'])
def test_vm_cp_b_w_auto(self): path_stack = './tests/stack_vm.stack' stack = qp.Stack('viewmanager').load(path_stack, load_cache=True) vm = ViewManager(stack) vm.get_views(cell_items='counts_colpct', freqs=True, nets=False, stats=None, tests=None, weight='weight_a', bases='auto') vm.set_bases('w', 'w', 'w', ['gross', 'base', 'effective']) vm_views = vm.views self.assertEqual(vm_views, E['cp_b_w_auto'])
def test_vm_p_b_n_s_t_w_both(self): path_stack = './tests/stack_vm.stack' stack = qp.Stack('viewmanager').load(path_stack, load_cache=True) vm = ViewManager(stack) vm.get_views(cell_items='colpct', freqs=True, nets=True, stats=['mean', 'stddev'], tests=['0.05'], weight='weight_a', bases='both') vm.set_bases('both', 'both', 'w', ['gross', 'base', 'effective'], 'before', True) vm_views = vm.views self.assertEqual(vm_views, E['p_b_n_s_t_w_both'])
def test_vm_p_b_w_both(self): path_stack = './tests/stack_vm.stack' stack = qp.Stack('viewmanager').load(path_stack, load_cache=True) vm = ViewManager(stack) vm.get_views(cell_items='colpct', freqs=True, nets=False, stats=None, tests=None, weight='weight_a', bases='both') vm.set_bases('both', 'both', 'w', ['gross', 'base', 'effective'], 'before', True) vm_views = vm.views self.assertEqual(vm_views, E['p_b_w_both']) path_cache = './tests/stack_vm.cache' os.remove(path_stack) os.remove(path_cache)
def test_vm_cp_b(self): path_stack = './tests/stack_vm.stack' stack = qp.Stack('viewmanager').load(path_stack, load_cache=True) vm = ViewManager(stack, basics=True, nets=False, stats=None, tests=None) vm_views = vm.get_views(cell_items='cp', weights=None, bases='auto').group().views self.assertEqual(vm_views, E['cp_b'])
def test_vm_p_b_n_s_t_w_both(self): path_stack = './tests/stack_vm.stack' stack = qp.Stack('viewmanager').load(path_stack, load_cache=True) vm = ViewManager(stack, basics=True, nets=True, stats=['mean', 'stddev'], tests=['0.05']) vm_views = vm.get_views(cell_items='p', weights='weight_a', bases='both').group().views self.assertEqual(vm_views, E['p_b_n_s_t_w_both'])