예제 #1
0
 def _swap_and_rebase(quantity, variable, axis='x'):
     rebase_on = {quantity.x: not_count(0)}
     org_x = quantity.x
     quantity.swap(var=variable, axis=axis, update_axis_def=False)
     try:
         quantity.filter(rebase_on, keep_base=False, inplace=True)
     except:
         warn = "Couldn't rebase 'source'-swapped array-type Quantity: {} "
         warn += "on {}\nPlease check descriptive stats results for correct "
         warn += "base sizes!"
         warnings.warn(warn.format(org_x, variable))
     return quantity
예제 #2
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'
        )
예제 #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'
     )
예제 #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')
예제 #5
0
    def test_has_not_count_errors(self):

        responses_tests = [
            [],
            [1, 2, 3, 4],
        ]
        for responses in responses_tests:
            # Test has version
            with self.assertRaises(IndexError) as error:
                func, values, exclusive = has_count(responses)
            self.assertEqual(
                error.exception.message[:85],
                "The responses list given to has_count() must have "
                "either 1, 2 or 3 items in the form:"
            )
            # Test not version
            with self.assertRaises(IndexError) as error:
                # Test _has_all raises TypeError
                func, values, exclusive = not_count(responses)
            self.assertEqual(
                error.exception.message[:85],
                "The responses list given to not_count() must have "
                "either 1, 2 or 3 items in the form:"
            )

        responses_tests = [
            '1',
            None,
            1.5,
            ['1'],
        ]
        for responses in responses_tests:
            # Test has version
            with self.assertRaises(TypeError) as error:
                func, values = has_count(responses)
            self.assertEqual(
                error.exception.message[:59],
                "The count target given to has_count() is "
                "incorrectly typed."
            )
            # Test not version
            with self.assertRaises(TypeError) as error:
                func, values = not_count(responses)
            self.assertEqual(
                error.exception.message[:59],
                "The count target given to not_count() is "
                "incorrectly typed."
            )

        responses_tests = [
            ['1', 2],
            [1, '2'],
            [None, 2],
            [2, None],
            [1.5, 2],
            [1, 2.5],
            [lambda x: x, 2],
            [1, is_lt]
        ]
        for responses in responses_tests:
            # Test has version
            with self.assertRaises(TypeError) as error:
                func, values = has_count(responses)
            self.assertEqual(
                error.exception.message[:63],
                "The values subset given to has_count() are "
                "not correctly typed."
            )
            # Test not version
            with self.assertRaises(TypeError) as error:
                func, values = not_count(responses)
            self.assertEqual(
                error.exception.message[:63],
                "The values subset given to not_count() are "
                "not correctly typed."
            )

        values_tests = copy.copy(responses_tests)
        [r.append([1, 2, 3]) for r in values_tests]
        for responses in values_tests:
            # Test has version
            with self.assertRaises(TypeError) as error:
                func, values = has_count(responses)
            self.assertEqual(
                error.exception.message[:63],
                "The values subset given to has_count() are "
                "not correctly typed."
            )
            # Test not version
            with self.assertRaises(TypeError) as error:
                func, values = not_count(responses)
            self.assertEqual(
                error.exception.message[:63],
                "The values subset given to not_count() are "
                "not correctly typed."
            )


        values_tests = [
            [1, 2, ['1', 2, 3]],
            [1, 2, [1, '2', 3]],
            [1, 2, [1, 2, '3']],
            [1, 2, [1.5, 2, 3]],
            [1, 2, [1, 2.5, 3]],
            [1, 2, [1, 2, 3.5]],
            [1, 2, [None, 2, 3]],
            [1, 2, [1, None, 3]],
            [1, 2, [1, 2, None]],
        ]
        for responses in values_tests:
            # Test has version
            with self.assertRaises(TypeError) as error:
                func, values = has_count(responses)
            self.assertEqual(
                error.exception.message[:63],
                "The values subset given to has_count() are"
                " not correctly typed."
            )
            # Test not version
            with self.assertRaises(TypeError) as error:
                func, values = not_count(responses)
            self.assertEqual(
                error.exception.message[:63],
                "The values subset given to not_count() are"
                " not correctly typed."
            )
예제 #6
0
    def test_has_not_count(self):
        # Test has versions
        func, values, exclusive = has_count(1)
        self.assertEqual(func, _has_count)
        self.assertEqual(values, [1])
        self.assertEqual(exclusive, False)

        func, values, exclusive = has_count([1])
        self.assertEqual(func, _has_count)
        self.assertEqual(values, [1])
        self.assertEqual(exclusive, False)

        test_values = [1, 3]
        func, values, exclusive = has_count(test_values)
        self.assertEqual(func, _has_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)

        test_values = [1, 3, [1, 2, 3]]
        func, values, exclusive = has_count(test_values)
        self.assertEqual(func, _has_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)

        test_values = [1, 3]
        func, values, exclusive = has_count(test_values)
        self.assertEqual(func, _has_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)

        test_values = [1, 3, [1, 2, 3]]
        func, values, exclusive = has_count(test_values)
        self.assertEqual(func, _has_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)

        for op_func in [is_lt, is_le, is_eq, is_ne, is_ge, is_gt]:

            test_values = [op_func(3)]
            func, values, exclusive = has_count(test_values)
            self.assertEqual(func, _has_count)
            self.assertEqual(values, test_values)
            self.assertEqual(exclusive, False)

            test_values = [op_func(3), [1, 2, 3]]
            func, values, exclusive = has_count(test_values)
            self.assertEqual(func, _has_count)
            self.assertEqual(values, test_values)
            self.assertEqual(exclusive, False)

        # Test not versions
        func, values, exclusive = not_count(1)
        self.assertEqual(func, _not_count)
        self.assertEqual(values, [1])
        self.assertEqual(exclusive, False)

        func, values, exclusive = not_count([1])
        self.assertEqual(func, _not_count)
        self.assertEqual(values, [1])
        self.assertEqual(exclusive, False)

        test_values = [1, 3]
        func, values, exclusive = not_count(test_values)
        self.assertEqual(func, _not_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)

        test_values = [1, 3, [1, 2, 3]]
        func, values, exclusive = not_count(test_values)
        self.assertEqual(func, _not_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)

        test_values = [1, 3]
        func, values, exclusive = not_count(test_values)
        self.assertEqual(func, _not_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)

        test_values = [1, 3, [1, 2, 3]]
        func, values, exclusive = not_count(test_values)
        self.assertEqual(func, _not_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)

        for op_func in [is_lt, is_le, is_eq, is_ne, is_ge, is_gt]:

            test_values = [op_func(3)]
            func, values, exclusive = not_count(test_values)
            self.assertEqual(func, _not_count)
            self.assertEqual(values, test_values)
            self.assertEqual(exclusive, False)

            test_values = [op_func(3), [1, 2, 3]]
            func, values, exclusive = not_count(test_values)
            self.assertEqual(func, _not_count)
            self.assertEqual(values, test_values)
            self.assertEqual(exclusive, False)
예제 #7
0
 def _swap_and_rebase(quantity, variable, axis='x'):
     rebase_on = {quantity.x: not_count(0)}
     quantity.swap(var=variable, axis=axis)
     quantity.filter(rebase_on, keep_base=False, inplace=True)
     return quantity
예제 #8
0
    def test_has_not_count_errors(self):

        responses_tests = [
            [],
            [1, 2, 3, 4],
        ]
        for responses in responses_tests:
            # Test has version
            with self.assertRaises(IndexError) as error:
                func, values, exclusive = has_count(responses)
            self.assertEqual(
                error.exception.message[:85],
                "The responses list given to has_count() must have "
                "either 1, 2 or 3 items in the form:"
            )
            # Test not version
            with self.assertRaises(IndexError) as error:
                # Test _has_all raises TypeError
                func, values, exclusive = not_count(responses)
            self.assertEqual(
                error.exception.message[:85],
                "The responses list given to not_count() must have "
                "either 1, 2 or 3 items in the form:"
            )
        
        responses_tests = [
            '1',
            None,
            1.5,
            ['1'],
        ]
        for responses in responses_tests:
            # Test has version
            with self.assertRaises(TypeError) as error:
                func, values = has_count(responses)
            self.assertEqual(
                error.exception.message[:59],
                "The count target given to has_count() is "
                "incorrectly typed."
            )
            # Test not version
            with self.assertRaises(TypeError) as error:
                func, values = not_count(responses)
            self.assertEqual(
                error.exception.message[:59],
                "The count target given to not_count() is "
                "incorrectly typed."
            )
          
        responses_tests = [
            ['1', 2],
            [1, '2'],
            [None, 2],
            [2, None],
            [1.5, 2],
            [1, 2.5],
            [lambda x: x, 2],
            [1, is_lt]
        ]          
        for responses in responses_tests:
            # Test has version
            with self.assertRaises(TypeError) as error:
                func, values = has_count(responses)
            self.assertEqual(
                error.exception.message[:63],
                "The values subset given to has_count() are "
                "not correctly typed."
            )
            # Test not version
            with self.assertRaises(TypeError) as error:
                func, values = not_count(responses)
            self.assertEqual(
                error.exception.message[:63],
                "The values subset given to not_count() are "
                "not correctly typed."
            )
        
        values_tests = copy.copy(responses_tests)
        [r.append([1, 2, 3]) for r in values_tests]      
        for responses in values_tests:
            # Test has version
            with self.assertRaises(TypeError) as error:
                func, values = has_count(responses)
            self.assertEqual(
                error.exception.message[:63],
                "The values subset given to has_count() are "
                "not correctly typed."
            )
            # Test not version
            with self.assertRaises(TypeError) as error:
                func, values = not_count(responses)
            self.assertEqual(
                error.exception.message[:63],
                "The values subset given to not_count() are "
                "not correctly typed."
            )
        
        
        values_tests = [
            [1, 2, ['1', 2, 3]],
            [1, 2, [1, '2', 3]],
            [1, 2, [1, 2, '3']],
            [1, 2, [1.5, 2, 3]],
            [1, 2, [1, 2.5, 3]],
            [1, 2, [1, 2, 3.5]],
            [1, 2, [None, 2, 3]],
            [1, 2, [1, None, 3]],
            [1, 2, [1, 2, None]],
        ]
        for responses in values_tests:
            # Test has version
            with self.assertRaises(TypeError) as error:
                func, values = has_count(responses)
            self.assertEqual(
                error.exception.message[:63],
                "The values subset given to has_count() are"
                " not correctly typed."
            )
            # Test not version
            with self.assertRaises(TypeError) as error:
                func, values = not_count(responses)
            self.assertEqual(
                error.exception.message[:63],
                "The values subset given to not_count() are"
                " not correctly typed."
            )
예제 #9
0
    def test_has_not_count(self):
        # Test has versions
        func, values, exclusive = has_count(1)
        self.assertEqual(func, _has_count)
        self.assertEqual(values, [1])
        self.assertEqual(exclusive, False)
 
        func, values, exclusive = has_count([1])
        self.assertEqual(func, _has_count)
        self.assertEqual(values, [1])
        self.assertEqual(exclusive, False)
 
        test_values = [1, 3]
        func, values, exclusive = has_count(test_values)
        self.assertEqual(func, _has_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)
 
        test_values = [1, 3, [1, 2, 3]]
        func, values, exclusive = has_count(test_values)
        self.assertEqual(func, _has_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)
 
        test_values = [1, 3]
        func, values, exclusive = has_count(test_values)
        self.assertEqual(func, _has_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)
 
        test_values = [1, 3, [1, 2, 3]]
        func, values, exclusive = has_count(test_values)
        self.assertEqual(func, _has_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)
 
        for op_func in [is_lt, is_le, is_eq, is_ne, is_ge, is_gt]:
            
            test_values = [op_func(3)]
            func, values, exclusive = has_count(test_values)
            self.assertEqual(func, _has_count)
            self.assertEqual(values, test_values)
            self.assertEqual(exclusive, False)
     
            test_values = [op_func(3), [1, 2, 3]]
            func, values, exclusive = has_count(test_values)
            self.assertEqual(func, _has_count)
            self.assertEqual(values, test_values)
            self.assertEqual(exclusive, False)

        # Test not versions
        func, values, exclusive = not_count(1)
        self.assertEqual(func, _not_count)
        self.assertEqual(values, [1])
        self.assertEqual(exclusive, False)
 
        func, values, exclusive = not_count([1])
        self.assertEqual(func, _not_count)
        self.assertEqual(values, [1])
        self.assertEqual(exclusive, False)
 
        test_values = [1, 3]
        func, values, exclusive = not_count(test_values)
        self.assertEqual(func, _not_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)
 
        test_values = [1, 3, [1, 2, 3]]
        func, values, exclusive = not_count(test_values)
        self.assertEqual(func, _not_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)
 
        test_values = [1, 3]
        func, values, exclusive = not_count(test_values)
        self.assertEqual(func, _not_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)
 
        test_values = [1, 3, [1, 2, 3]]
        func, values, exclusive = not_count(test_values)
        self.assertEqual(func, _not_count)
        self.assertEqual(values, test_values)
        self.assertEqual(exclusive, False)
 
        for op_func in [is_lt, is_le, is_eq, is_ne, is_ge, is_gt]:
            
            test_values = [op_func(3)]
            func, values, exclusive = not_count(test_values)
            self.assertEqual(func, _not_count)
            self.assertEqual(values, test_values)
            self.assertEqual(exclusive, False)
     
            test_values = [op_func(3), [1, 2, 3]]
            func, values, exclusive = not_count(test_values)
            self.assertEqual(func, _not_count)
            self.assertEqual(values, test_values)
            self.assertEqual(exclusive, False)