コード例 #1
0
def test_to_dict():
    tax_scale = taxscales.SingleAmountTaxScale()
    tax_scale.add_bracket(6, 0.23)
    tax_scale.add_bracket(9, 0.29)

    result = tax_scale.to_dict()

    assert result == {"6": 0.23, "9": 0.29}
def test_calc_interpolate_with_unitary_bracket():
    tax_base = numpy.array([2.5, 5, 7, 10])
    tax_scale = taxscales.SingleAmountTaxScale()
    tax_scale.add_bracket(5, 50)

    result = tax_scale.calc(tax_base, interpolate=True)

    tools.assert_near(result, [50, 50, 50, 50])
コード例 #3
0
def test_calc():
    tax_base = numpy.array([1, 8, 10])
    tax_scale = taxscales.SingleAmountTaxScale()
    tax_scale.add_bracket(6, 0.23)
    tax_scale.add_bracket(9, 0.29)

    result = tax_scale.calc(tax_base)

    tools.assert_near(result, [0, 0.23, 0.29])
def test_calc_interpolate():
    tax_base = numpy.array([2.5, 5, 7, 10])
    tax_scale = taxscales.SingleAmountTaxScale()
    tax_scale.add_bracket(0, 0)
    tax_scale.add_bracket(5, 50)
    tax_scale.add_bracket(10, 200)

    result = tax_scale.calc(tax_base, interpolate=True)

    tools.assert_near(result, [25, 50, 110, 200])
コード例 #5
0
ファイル: parameters.py プロジェクト: cbenz/openfisca-core
    def _get_at_instant(self, instant):
        brackets = [
            bracket.get_at_instant(instant) for bracket in self.brackets
        ]

        if self.metadata.get('type') == 'single_amount':
            scale = taxscales.SingleAmountTaxScale()
            for bracket in brackets:
                if 'amount' in bracket._children and 'threshold' in bracket._children:
                    amount = bracket.amount
                    threshold = bracket.threshold
                    scale.add_bracket(threshold, amount)
            return scale
        elif any('amount' in bracket._children for bracket in brackets):
            scale = taxscales.MarginalAmountTaxScale()
            for bracket in brackets:
                if 'amount' in bracket._children and 'threshold' in bracket._children:
                    amount = bracket.amount
                    threshold = bracket.threshold
                    scale.add_bracket(threshold, amount)
            return scale
        elif any('average_rate' in bracket._children for bracket in brackets):
            scale = taxscales.LinearAverageRateTaxScale()

            for bracket in brackets:
                if 'base' in bracket._children:
                    base = bracket.base
                else:
                    base = 1.
                if 'average_rate' in bracket._children and 'threshold' in bracket._children:
                    average_rate = bracket.average_rate
                    threshold = bracket.threshold
                    scale.add_bracket(threshold, average_rate * base)
            return scale
        else:
            scale = taxscales.MarginalRateTaxScale()

            for bracket in brackets:
                if 'base' in bracket._children:
                    base = bracket.base
                else:
                    base = 1.
                if 'rate' in bracket._children and 'threshold' in bracket._children:
                    rate = bracket.rate
                    threshold = bracket.threshold
                    scale.add_bracket(threshold, rate * base)
            return scale