From 8b3e9e8e4ea1b95cdb2cd43e2440d0f381361521 Mon Sep 17 00:00:00 2001 From: Maximiliano Greco Date: Mon, 21 Feb 2022 19:42:06 +0100 Subject: [PATCH] cln: rename top_rest ratio closes #35 --- src/ineqpy/api.py | 4 ++-- src/ineqpy/inequality.py | 4 ++-- tests/test_inequality.py | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ineqpy/api.py b/src/ineqpy/api.py index 278dfcd..00b7b05 100644 --- a/src/ineqpy/api.py +++ b/src/ineqpy/api.py @@ -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. @@ -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) diff --git a/src/ineqpy/inequality.py b/src/ineqpy/inequality.py index b11348c..0eb5154 100644 --- a/src/ineqpy/inequality.py +++ b/src/ineqpy/inequality.py @@ -27,7 +27,7 @@ "lorenz", "reynolds_smolensky", "theil", - "ratio_top_rest", + "top_rest", "hoover", ] @@ -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 diff --git a/tests/test_inequality.py b/tests/test_inequality.py index 6e527c3..b5edab1 100644 --- a/tests/test_inequality.py +++ b/tests/test_inequality.py @@ -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 @@ -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(): @@ -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