Beispiel #1
0
 def test_interlock(self):
     dataset = self._get_dataset()
     data = dataset._data
     name, lab = 'q4AgeGen', 'q4 Age Gender'
     variables = [
         'q4', {
             'age': [(1, '18-35', {
                 'age': frange('18-35')
             }), (2, '30-49', {
                 'age': frange('30-49')
             }), (3, '50+', {
                 'age': is_ge(50)
             })]
         }, 'gender'
     ]
     dataset.interlock(name, lab, variables)
     val = [1367, 1109, 1036, 831, 736, 579, 571, 550, 454, 438, 340, 244]
     ind = [
         '10;', '8;', '9;', '7;', '3;', '8;10;', '1;', '4;', '2;', '7;9;',
         '1;3;', '2;4;'
     ]
     s = pd.Series(val, index=ind, name='q4AgeGen')
     self.assertTrue(all(s == data['q4AgeGen'].value_counts()))
     values = [(1, u'Yes/18-35/Male'), (2, u'Yes/18-35/Female'),
               (3, u'Yes/30-49/Male'), (4, u'Yes/30-49/Female'),
               (5, u'Yes/50+/Male'), (6, u'Yes/50+/Female'),
               (7, u'No/18-35/Male'), (8, u'No/18-35/Female'),
               (9, u'No/30-49/Male'), (10, u'No/30-49/Female'),
               (11, u'No/50+/Male'), (12, u'No/50+/Female')]
     text = 'q4 Age Gender'
     self.assertEqual(values, dataset.values('q4AgeGen'))
     self.assertEqual(text, dataset.text('q4AgeGen'))
     self.assertTrue(dataset.is_delimited_set('q4AgeGen'))
 def test_get_logic_key(self):
     
     logic = has_all([1, 2, 3], True)
     self.assertEqual(
         get_logic_key(logic),
         'x[e(1&2&3)]:y'
     )
     
     logic = has_count([is_ge(1), [5, 6, 7, 8, 9]])
     self.assertEqual(
         get_logic_key(logic),
         'x[(5,6,7,8,9){>=1}]:y'
     )
     
     logic = not_count([is_ge(1), [5, 6, 7, 8, 9]])
     self.assertEqual(
         get_logic_key(logic),
         'x[(5,6,7,8,9)~{>=1}]:y'
     )
     
     logic = union([
         has_any([1, 2]), 
         has_all([3, 4]), 
         not_any([5, 6])
     ])
     self.assertEqual(
         get_logic_key(logic),
         'x[((1,2),(3&4),~(5,6))]:y'
     )
     
     logic = union([
         intersection([
             has_any([1, 2]),
             not_any([3])
         ]),
         {'Wave': has_any([1,2])}
     ])
     self.assertEqual(
         get_logic_key(logic, self.example_data_A_data),
         'x[(((1,2)&~(3)),Wave=(1,2))]:y'
     )
Beispiel #3
0
    def test_get_logic_key(self):

        logic = has_all([1, 2, 3], True)
        self.assertEqual(
            get_logic_key(logic),
            'x[e{1&2&3}]:y'
        )

        logic = has_count([is_ge(1), [5, 6, 7, 8, 9]])
        self.assertEqual(
            get_logic_key(logic),
            'x[(5,6,7,8,9){>=1}]:y'
        )

        logic = not_count([is_ge(1), [5, 6, 7, 8, 9]])
        self.assertEqual(
            get_logic_key(logic),
            'x[(5,6,7,8,9)~{>=1}]:y'
        )

        logic = union([
            has_any([1, 2]),
            has_all([3, 4]),
            not_any([5, 6])
        ])
        self.assertEqual(
            get_logic_key(logic),
            'x[({1,2},{3&4},~{5,6})]:y'
        )

        logic = union([
            intersection([
                has_any([1, 2]),
                not_any([3])
            ]),
            {'Wave': has_any([1,2])}
        ])
        self.assertEqual(
            get_logic_key(logic, self.example_data_A_data),
            'x[(({1,2}&~{3}),Wave={1,2})]:y'
        )
Beispiel #4
0
    def test_get_logic_key(self):

        logic = has_all([1, 2, 3], True)
        self.assertEqual(get_logic_key(logic), 'x[e(1&2&3)]:y')

        logic = has_count([is_ge(1), [5, 6, 7, 8, 9]])
        self.assertEqual(get_logic_key(logic), 'x[(5,6,7,8,9){>=1}]:y')

        logic = not_count([is_ge(1), [5, 6, 7, 8, 9]])
        self.assertEqual(get_logic_key(logic), 'x[(5,6,7,8,9)~{>=1}]:y')

        logic = union([has_any([1, 2]), has_all([3, 4]), not_any([5, 6])])
        self.assertEqual(get_logic_key(logic), 'x[((1,2),(3&4),~(5,6))]:y')

        logic = union([
            intersection([has_any([1, 2]), not_any([3])]), {
                'Wave': has_any([1, 2])
            }
        ])
        self.assertEqual(get_logic_key(logic, self.example_data_A_data),
                         'x[(((1,2)&~(3)),Wave=(1,2))]:y')
    def test_simple_or(self):

        # Test single x stored as int64 and float64
        for xk in ['Wave', 'ethnicity']:
            # Initial setup
            values = [1, 2, 3]
            yks = ['@', 'ethnicity', 'q2', 'gender']

            # Set up basic stack
            self.setup_stack_Example_Data_A()

            # Test net created using an OR list with 'codes'
            method_name = 'codes_list'
            self.net_views.add_method(
                name=method_name,
                kwargs={'text': 'Ever', 'logic': values, 'axis': 'x'}
            )
            self.stack.add_link(x=xk, views=self.net_views.subset([method_name]))
            relation = 'x[{1,2,3}]:'
            self.verify_net_values_single_x(self.stack, xk, yks, values, relation, method_name)

            # Test net created using an OR list with 'logic'
            method_name = 'logic_list'
            self.net_views.add_method(
                name=method_name,
                kwargs={'text': 'Ever', 'logic': values, 'axis': 'x'}
            )
            self.stack.add_link(x=xk, views=self.net_views.subset([method_name]))
            relation = 'x[{1,2,3}]:'
            self.verify_net_values_single_x(self.stack, xk, yks, values, relation, method_name)

            # Test net created using has_any() logic
            method_name = 'has_any'
            self.net_views.add_method(
                name=method_name,
                kwargs={'text': 'Ever', 'logic': has_any([1,2,3]), 'axis': 'x'}
            )
            self.stack.add_link(x=xk, views=self.net_views.subset([method_name]))
            relation = 'x[{1,2,3}]:'
            self.verify_net_values_single_x(self.stack, xk, yks, values, relation, method_name)

            # Test net created using has_count() logic
            method_name = 'has_count'
            self.net_views.add_method(
                name=method_name,
                kwargs={'text': 'Ever',
                        'logic': has_count([is_ge(1), [1,2,3]]), 'axis': 'x'}
            )
            self.stack.add_link(x=xk, views=self.net_views.subset([method_name]))
            relation = 'x[(1,2,3){>=1}]:'
            self.verify_net_values_single_x(self.stack, xk, yks, values, relation, method_name)
 def test_simple_or(self):
     
     # Test single x stored as int64 and float64
     for xk in ['Wave', 'ethnicity']:
         # Initial setup
         values = [1, 2, 3]
         yks = ['@', 'ethnicity', 'q2', 'gender']
         
         # Set up basic stack
         self.setup_stack_Example_Data_A()
         
         # Test net created using an OR list with 'codes'
         method_name = 'codes_list'
         self.net_views.add_method(
             name=method_name, 
             kwargs={'text': 'Ever', 'logic': values}
         )
         self.stack.add_link(x=xk, views=self.net_views.subset([method_name]))
         relation = 'x[(1,2,3)]:y'
         self.verify_net_values_single_x(self.stack, xk, yks, values, relation, method_name)
          
         # Test net created using an OR list with 'logic'
         method_name = 'logic_list'
         self.net_views.add_method(
             name=method_name, 
             kwargs={'text': 'Ever', 'logic': values}
         )
         self.stack.add_link(x=xk, views=self.net_views.subset([method_name]))
         relation = 'x[(1,2,3)]:y'
         self.verify_net_values_single_x(self.stack, xk, yks, values, relation, method_name)
          
         # Test net created using has_any() logic
         method_name = 'has_any'
         self.net_views.add_method(
             name=method_name, 
             kwargs={'text': 'Ever', 'logic': has_any([1,2,3])}
         )
         self.stack.add_link(x=xk, views=self.net_views.subset([method_name]))
         relation = 'x[(1,2,3)]:y'
         self.verify_net_values_single_x(self.stack, xk, yks, values, relation, method_name)
         
         # Test net created using has_count() logic
         method_name = 'has_count'
         self.net_views.add_method(
             name=method_name, 
             kwargs={'text': 'Ever', 'logic': has_count([is_ge(1), [1,2,3]])}
         )
         self.stack.add_link(x=xk, views=self.net_views.subset([method_name]))
         relation = 'x[(1,2,3){>=1}]:y'
         self.verify_net_values_single_x(self.stack, xk, yks, values, relation, method_name)
Beispiel #7
0
 def test_add_open_ends(self):
     batch, ds = _get_batch('test')
     self.assertRaises(ValueError, batch.add_open_ends, ['q8a', 'q9a'],
                       None, True, False, True, 'open ends', None)
     batch.add_filter('men only', {'gender': 1})
     batch.add_open_ends(['q8a', 'q9a'],
                         'RecordNo',
                         filter_by={'age': is_ge(49)})
     b_meta = _get_meta(batch)
     self.assertEqual(b_meta['verbatims']['open ends'].shape, (40, 3))
     self.assertEqual(b_meta['verbatim_names'], ['q8a', 'q9a'])
     batch.add_open_ends(['q8a', 'q9a'],
                         'RecordNo',
                         split=True,
                         title=['open ends', 'open ends2'])
     self.assertEqual(b_meta['verbatims'].keys(),
                      ['open ends', 'open ends2'])
Beispiel #8
0
 def test_add_open_ends(self):
     batch, ds = _get_batch('test')
     self.assertRaises(ValueError, batch.add_open_ends, ['q8a', 'q9a'],
                       None, True, False, True, 'open ends', None)
     batch.add_filter('men_only', {'gender': 1})
     batch.add_open_ends(['q8a', 'q9a'],
                         'RecordNo',
                         filter_by={'age': is_ge(49)})
     verbatims = _get_meta(batch)['verbatims'][0]
     self.assertEqual(verbatims['filter'], 'men_only_open_ends_f')
     self.assertEqual(verbatims['columns'], ['q8a', 'q9a'])
     self.assertEqual(verbatims['break_by'], ['RecordNo'])
     self.assertEqual(verbatims['title'], 'open ends')
     batch.add_open_ends(['q8a', 'q9a'],
                         'RecordNo',
                         split=True,
                         title=['open ends', 'open ends2'],
                         overwrite=True)
     verbatims = _get_meta(batch)['verbatims']
     self.assertEqual(len(verbatims), 2)
Beispiel #9
0
 def test_is_ge(self):
     test_value = 5
     func, value = is_ge(test_value)
     self.assertEqual(func, _is_ge)
     self.assertEqual(value, test_value)
 def test_is_ge(self):
     test_value = 5
     func, value = is_ge(test_value)
     self.assertEqual(func, _is_ge)
     self.assertEqual(value, test_value)