22
33
44def average_rate (target = None , varying = None , trim = None ):
5- '''
6- Computes the average rate of a targeted net income, according to the varying gross income.
5+ """Computes the average rate of a target net income.
76
8- :param target: Targeted net income, numerator
9- :param varying: Varying gross income, denominator
10- :param trim: Lower and upper bound of average rate to return
7+ Given a ``target`` net income, and according to the ``varying`` gross
8+ income. Optionally, a ``trim`` can be applied consisting of the lower and
9+ upper bounds of the average rate to be computed.
10+
11+ Note:
12+ Usually, ``target`` and ``varying`` are the same size.
13+
14+ Args:
15+ target: The targeted net income.
16+ varying: The varying gross income.
17+ trim: The lower and upper bounds of the average rate.
18+
19+ Returns:
20+ :obj:`numpy.ndarray` of :obj:`float`:
21+
22+ The average rate for each target.
23+
24+ When ``trim`` is provided, values that are out of the provided bounds
25+ are replaced by :obj:`numpy.nan`.
1126
1227 Examples:
1328 >>> target = numpy.array([1, 2, 3])
@@ -16,7 +31,7 @@ def average_rate(target = None, varying = None, trim = None):
1631 >>> average_rate(target, varying, trim)
1732 array([ nan, 0. , -0.5])
1833
19- '''
34+ """
2035
2136 average_rate = 1 - target / varying
2237 if trim is not None :
@@ -27,7 +42,27 @@ def average_rate(target = None, varying = None, trim = None):
2742
2843
2944def marginal_rate (target = None , varying = None , trim = None ):
30- """
45+ """Computes the marginal rate of a target net income.
46+
47+ Given a ``target`` net income, and according to the ``varying`` gross
48+ income. Optionally, a ``trim`` can be applied consisting of the lower and
49+ upper bounds of the marginal rate to be computed.
50+
51+ Note:
52+ Usually, ``target`` and ``varying`` are the same size.
53+
54+ Args:
55+ target: The targeted net income.
56+ varying: The varying gross income.
57+ trim: The lower and upper bounds of the marginal rate.
58+
59+ Returns:
60+ :obj:`numpy.ndarray` of :obj:`float`:
61+
62+ The marginal rate for each target.
63+
64+ When ``trim`` is provided, values that are out of the provided bounds
65+ are replaced by :obj:`numpy.nan`.
3166
3267 Examples:
3368 >>> target = numpy.array([1, 2, 3])
@@ -38,7 +73,6 @@ def marginal_rate(target = None, varying = None, trim = None):
3873
3974 """
4075
41- # target: numerator, varying: denominator
4276 marginal_rate = 1 - (target [:- 1 ] - target [1 :]) / (varying [:- 1 ] - varying [1 :])
4377 if trim is not None :
4478 marginal_rate = numpy .where (marginal_rate <= max (trim ), marginal_rate , numpy .nan )
0 commit comments