Skip to content

Commit

Permalink
cln: rename top_rest ratio
Browse files Browse the repository at this point in the history
closes #35
  • Loading branch information
mmngreco committed Feb 21, 2022
1 parent cee8ee6 commit 8b3e9e8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/ineqpy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def avg_tax_rate(self, total_tax, total_base, weights=None):

return inequality.avg_tax_rate(total_tax, total_base, weights, data)

def ratio_top_rest(
def top_rest(
self, income, weights=None, data=None, top_percentage=10
):
"""Calculate the 10:90 Ratio.
Expand Down Expand Up @@ -793,4 +793,4 @@ def ratio_top_rest(
if weights is None:
weights = self.weights

return inequality.ratio_top_rest(income, weights, data, top_percentage)
return inequality.top_rest(income, weights, data, top_percentage)
4 changes: 2 additions & 2 deletions src/ineqpy/inequality.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"lorenz",
"reynolds_smolensky",
"theil",
"ratio_top_rest",
"top_rest",
"hoover",
]

Expand Down Expand Up @@ -456,7 +456,7 @@ def avg_tax_rate(total_tax, total_base, weights=None, data=None):
return res


def ratio_top_rest(income, weights=None, data=None, top_percentage=10.0):
def top_rest(income, weights=None, data=None, top_percentage=10.0):
"""Calculate the 10:90 Ratio.
Calculates the quotient between the number of contributions from the top
Expand Down
14 changes: 7 additions & 7 deletions tests/test_inequality.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ def test_theil_1d_1_w():
def test_ratio_eqaulity():
x = np.array([1, 9])
w = np.array([9, 1])
obtained = inequality.ratio_top_rest(income=x, weights=w)
obtained = inequality.top_rest(income=x, weights=w)
assert obtained == 1.0

def test_ratio_equality_fracc():
x = np.array([1, 9])
w = np.array([.9, .1])
obtained = inequality.ratio_top_rest(income=x, weights=w)
obtained = inequality.top_rest(income=x, weights=w)
assert obtained == 1.0

def test_ratio_1d():
x = np.array([57, 63, 81, 79, 88, 42, 3, 77, 89])
w = np.array([9, 5, 2, 9, 5, 4, 5, 9, 9])
obtained = inequality.ratio_top_rest(income=x, weights=w)
obtained = inequality.top_rest(income=x, weights=w)
expected = pytest.approx(0.15323043465128208)
assert obtained == expected

def test_ratio_2d():
x = np.array([[57], [63], [81], [79], [88], [42], [3], [77], [89]])
w = np.array([[9], [5], [2], [9], [5], [4], [5], [9], [9]])
obtained = inequality.ratio_top_rest(income=x, weights=w)
obtained = inequality.top_rest(income=x, weights=w)
expected = pytest.approx(0.15323043465128208)
assert obtained == expected

Expand All @@ -125,8 +125,8 @@ def test_ratio_weighted_eq_unweighted(n):

assert len(xw) == np.sum(w)

weighted = inequality.ratio_top_rest(income=x, weights=w)
unweighted = inequality.ratio_top_rest(income=xw)
weighted = inequality.top_rest(income=x, weights=w)
unweighted = inequality.top_rest(income=xw)
assert pytest.approx(weighted) == unweighted

def test_ratio_unweighted():
Expand All @@ -137,7 +137,7 @@ def test_ratio_unweighted():
97, 77, 94, 66, 84, 42, 39, 7, 24, 65, 52, 59, 52, 38, 27, 85, 43,
26, 6, 93, 24, 48, 42, 50, 58, 89, 79, 94, 50, 2, 46, 82, 98, 69,
9, 50, 33, 86, 77, 25, 39, 61, 78, 47, 29, 43, 20, 56, 35])
obtained = inequality.ratio_top_rest(x)
obtained = inequality.top_rest(x)
expected = 0.22203712517848642
assert pytest.approx(obtained) == expected

Expand Down

0 comments on commit 8b3e9e8

Please sign in to comment.