From cd263f7202901c1e90b040c139eab7ca25c41b91 Mon Sep 17 00:00:00 2001 From: Serge Rey Date: Wed, 24 Apr 2024 08:33:12 -0700 Subject: [PATCH 01/12] deprecation of _indices --- inequality/_indices.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/inequality/_indices.py b/inequality/_indices.py index 9919882..3f500a4 100644 --- a/inequality/_indices.py +++ b/inequality/_indices.py @@ -11,6 +11,9 @@ :cite:`nijkamp2015cultural` https://www.econstor.eu/bitstream/10419/107568/1/dp8782.pdf """ +import warnings + +warnings.warn("The module _indices is deprecated and will be removed on 2025-01-01.", DeprecationWarning) import itertools From e113ffc36b6c7e7e682b68d60c035ad58175f17c Mon Sep 17 00:00:00 2001 From: Sergio Rey Date: Wed, 24 Apr 2024 09:10:36 -0700 Subject: [PATCH 02/12] Update inequality/_indices.py Co-authored-by: James Gaboardi --- inequality/_indices.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/inequality/_indices.py b/inequality/_indices.py index 3f500a4..46d2b75 100644 --- a/inequality/_indices.py +++ b/inequality/_indices.py @@ -13,7 +13,11 @@ """ import warnings -warnings.warn("The module _indices is deprecated and will be removed on 2025-01-01.", DeprecationWarning) +warnings.warn( + "The module _indices is deprecated and will be removed on 2025-01-01.", + DeprecationWarning, + stacklevel=2 +) import itertools From 58faac223f58be49709a0a34fe7f66b8e6cbdc7b Mon Sep 17 00:00:00 2001 From: Sergio Rey Date: Fri, 17 May 2024 02:28:08 -0700 Subject: [PATCH 03/12] Update inequality/_indices.py Co-authored-by: James Gaboardi --- inequality/_indices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inequality/_indices.py b/inequality/_indices.py index 46d2b75..dd60cdb 100644 --- a/inequality/_indices.py +++ b/inequality/_indices.py @@ -15,7 +15,7 @@ warnings.warn( "The module _indices is deprecated and will be removed on 2025-01-01.", - DeprecationWarning, + FutureWarning, stacklevel=2 ) From 300210b18695b0beeae29ab1ea613c0a80e6a40b Mon Sep 17 00:00:00 2001 From: Serge Rey Date: Wed, 14 Aug 2024 15:33:50 -0700 Subject: [PATCH 04/12] Deprecate indices --- inequality/_indices.py | 156 +++++++++++++++-------------------------- 1 file changed, 57 insertions(+), 99 deletions(-) diff --git a/inequality/_indices.py b/inequality/_indices.py index 3f500a4..e8ac698 100644 --- a/inequality/_indices.py +++ b/inequality/_indices.py @@ -11,17 +11,29 @@ :cite:`nijkamp2015cultural` https://www.econstor.eu/bitstream/10419/107568/1/dp8782.pdf """ +import numpy +import itertools import warnings +import functools -warnings.warn("The module _indices is deprecated and will be removed on 2025-01-01.", DeprecationWarning) -import itertools +SMALL = numpy.finfo("float").tiny -import numpy -SMALL = numpy.finfo("float").tiny +def deprecated_function(func): + """Decorator to mark functions as deprecated.""" + @functools.wraps(func) + def wrapper(*args, **kwargs): + warnings.warn( + f"{func.__name__} is deprecated and will be removed on 2025-01-01.", + DeprecationWarning, + stacklevel=2 + ) + return func(*args, **kwargs) + return wrapper +@deprecated_function def abundance(x): """ Abundance index. :cite:`nijkamp2015cultural` @@ -44,7 +56,7 @@ def abundance(x): >>> import numpy >>> x = numpy.array([[0, 1, 2], [0, 2, 4], [0, 0, 3]]) - >>> abundance(x) + >>> int(abundance(x)) 2 """ @@ -54,6 +66,7 @@ def abundance(x): return a +@deprecated_function def margalev_md(x): """ Margalev MD index. :cite:`nijkamp2015cultural` @@ -76,7 +89,7 @@ def margalev_md(x): >>> import numpy >>> x = numpy.array([[0, 1, 2], [0, 2, 4], [0, 0, 3]]) - >>> margalev_md(x) + >>> float(margalev_md(x)) 0.40242960438184466 """ @@ -86,6 +99,7 @@ def margalev_md(x): return mmd +@deprecated_function def menhinick_mi(x): """ Menhinick MI index. :cite:`nijkamp2015cultural` @@ -108,7 +122,7 @@ def menhinick_mi(x): >>> import numpy >>> x = numpy.array([[0, 1, 2], [0, 2, 4], [0, 0, 3]]) - >>> menhinick_mi(x) + >>> float(menhinick_mi(x)) 0.2886751345948129 """ @@ -118,6 +132,7 @@ def menhinick_mi(x): return mmi +@deprecated_function def simpson_so(x): """ Simpson diversity index SO. :cite:`nijkamp2015cultural` @@ -140,7 +155,7 @@ def simpson_so(x): >>> import numpy >>> x = numpy.array([[0, 1, 2], [0, 2, 4], [0, 0, 3]]) - >>> simpson_so(x) + >>> float(simpson_so(x)) 0.5909090909090909 """ @@ -153,6 +168,7 @@ def simpson_so(x): return sso +@deprecated_function def simpson_sd(x): """ Simpson diversity index SD. :cite:`nijkamp2015cultural` @@ -175,7 +191,7 @@ def simpson_sd(x): >>> import numpy >>> x = numpy.array([[0, 1, 2], [0, 2, 4], [0, 0, 3]]) - >>> simpson_sd(x) + >>> float(simpson_sd(x)) 0.40909090909090906 """ @@ -184,6 +200,7 @@ def simpson_sd(x): return ssd +@deprecated_function def herfindahl_hd(x): """ Herfindahl index HD. :cite:`nijkamp2015cultural` @@ -206,7 +223,7 @@ def herfindahl_hd(x): >>> import numpy >>> x = numpy.array([[0, 1, 2], [0, 2, 4], [0, 0, 3]]) - >>> herfindahl_hd(x) + >>> float(herfindahl_hd(x)) 0.625 """ @@ -217,6 +234,7 @@ def herfindahl_hd(x): return hhd +@deprecated_function def theil_th(x, ridz=True): """ Theil index TH as expressed in equation (32) of [2]. :cite:`nijkamp2015cultural` @@ -241,7 +259,7 @@ def theil_th(x, ridz=True): >>> import numpy >>> x = numpy.array([[0, 1, 2], [0, 2, 4], [0, 0, 3]]) - >>> theil_th(x) + >>> float(theil_th(x)) 0.15106563978903298 """ @@ -258,6 +276,7 @@ def theil_th(x, ridz=True): return tth +@deprecated_function def theil_th_brute(x, ridz=True): """ Theil index TH using inefficient computation. @@ -298,6 +317,7 @@ def theil_th_brute(x, ridz=True): return tth +@deprecated_function def fractionalization_gs(x): """ Fractionalization Gini-Simpson index GS. :cite:`nijkamp2015cultural` @@ -320,7 +340,7 @@ def fractionalization_gs(x): >>> import numpy >>> x = numpy.array([[0, 1, 2], [0, 2, 4], [0, 0, 3]]) - >>> fractionalization_gs(x) + >>> float(fractionalization_gs(x)) 0.375 """ @@ -329,10 +349,12 @@ def fractionalization_gs(x): return fgs +@deprecated_function def polarization(x): # noqa ARG001 raise RuntimeError("Not currently implemented.") +@deprecated_function def shannon_se(x): """ Shannon index SE. :cite:`nijkamp2015cultural` @@ -356,13 +378,7 @@ def shannon_se(x): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> y - array([[6, 1, 4], - [4, 8, 4], - [6, 3, 5], - [8, 7, 9]]) - - >>> shannon_se(y) + >>> float(shannon_se(y)) 1.094070862104929 """ @@ -374,6 +390,7 @@ def shannon_se(x): return sse +@deprecated_function def _gini(ys): """Gini for a single row to be used both by ``gini_gi`` and ``gini_gig``.""" @@ -384,6 +401,7 @@ def _gini(ys): return (num / den) - ((n + 1.0) / n) +@deprecated_function def gini_gi(x): """ Gini GI index. :cite:`nijkamp2015cultural` @@ -415,13 +433,7 @@ def gini_gi(x): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> y - array([[6, 1, 4], - [4, 8, 4], - [6, 3, 5], - [8, 7, 9]]) - - >>> round(gini_gi(y), 10) + >>> float(round(gini_gi(y), 10)) 0.0512820513 """ @@ -429,6 +441,7 @@ def gini_gi(x): return _gini(ys) +@deprecated_function def gini_gig(x): """ Gini GI index. :cite:`nijkamp2015cultural` @@ -456,12 +469,6 @@ def gini_gig(x): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> y - array([[6, 1, 4], - [4, 8, 4], - [6, 3, 5], - [8, 7, 9]]) - >>> gini_gig(y) array([0.125 , 0.32894737, 0.18181818]) @@ -471,6 +478,7 @@ def gini_gig(x): return ggig +@deprecated_function def gini_gi_m(x): """ Gini GI index (equivalent to ``gini_gi``, not vectorized). @@ -501,24 +509,20 @@ def gini_gi_m(x): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> y - array([[6, 1, 4], - [4, 8, 4], - [6, 3, 5], - [8, 7, 9]]) - - >>> round(gini_gi_m(y), 10) + >>> float(round(gini_gi_m(y), 10)) 0.0512820513 """ xs = x.sum(axis=0) - num = numpy.sum([numpy.abs(xi - xj) for xi, xj in itertools.permutations(xs, 2)]) + num = numpy.sum([numpy.abs(xi - xj) + for xi, xj in itertools.permutations(xs, 2)]) den = 2.0 * xs.shape[0] ** 2 * numpy.mean(xs) ggim = num / den return ggim +@deprecated_function def hoover_hi(x): """ Hoover index HI. :cite:`nijkamp2015cultural` @@ -546,14 +550,8 @@ def hoover_hi(x): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> y - array([[6, 1, 4], - [4, 8, 4], - [6, 3, 5], - [8, 7, 9]]) - - >>> round(hoover_hi(y), 10) - 0.041025641 + >>> f'{hoover_hi(y):.3f}' + '0.041' """ @@ -565,6 +563,7 @@ def hoover_hi(x): return hhi +@deprecated_function def similarity_w_wd(x, tau): """ Similarity weighted diversity. :cite:`nijkamp2015cultural` @@ -592,12 +591,6 @@ def similarity_w_wd(x, tau): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> y - array([[6, 1, 4], - [4, 8, 4], - [6, 3, 5], - [8, 7, 9]]) - >>> numpy.random.seed(0) >>> tau = numpy.random.uniform(size=(3,3)) >>> numpy.fill_diagonal(tau, 0.) @@ -607,8 +600,8 @@ def similarity_w_wd(x, tau): [0.63003627, 0. , 0.76883356], [0.52017529, 0.76883356, 0. ]]) - >>> round(similarity_w_wd(y, tau), 10) - 0.581859634 + >>> f'{similarity_w_wd(y, tau):.3f}' + '0.582' """ @@ -624,6 +617,7 @@ def similarity_w_wd(x, tau): return swwd +@deprecated_function def segregation_gsg(x): """ Segregation index GS. @@ -649,12 +643,6 @@ def segregation_gsg(x): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> y - array([[6, 1, 4], - [4, 8, 4], - [6, 3, 5], - [8, 7, 9]]) - >>> segregation_gsg(y).round(6) array([0.182927, 0.24714 , 0.097252]) @@ -671,6 +659,7 @@ def segregation_gsg(x): return sgsg +@deprecated_function def modified_segregation_msg(x): """ Modified segregation index GS. @@ -697,12 +686,6 @@ def modified_segregation_msg(x): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> y - array([[6, 1, 4], - [4, 8, 4], - [6, 3, 5], - [8, 7, 9]]) - >>> modified_segregation_msg(y).round(6) array([0.085207, 0.102249, 0.04355 ]) @@ -718,6 +701,7 @@ def modified_segregation_msg(x): return ms_inds +@deprecated_function def isolation_isg(x): """ Isolation index IS. :cite:`nijkamp2015cultural` @@ -741,12 +725,6 @@ def isolation_isg(x): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> y - array([[6, 1, 4], - [4, 8, 4], - [6, 3, 5], - [8, 7, 9]]) - >>> isolation_isg(y).round(6) array([1.07327 , 1.219953, 1.022711]) @@ -759,6 +737,7 @@ def isolation_isg(x): return iisg +@deprecated_function def isolation_ii(x): """ Isolation index :math:`II_g` as in equation (23) of [2]. @@ -783,12 +762,6 @@ def isolation_ii(x): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> y - array([[6, 1, 4], - [4, 8, 4], - [6, 3, 5], - [8, 7, 9]]) - >>> isolation_ii(y).round(6) array([1.11616 , 1.310804, 1.03433 ]) @@ -806,6 +779,7 @@ def isolation_ii(x): return iso_ii +@deprecated_function def ellison_glaeser_egg(x, hs=None): """ Ellison and Glaeser (1997) :cite:`ellison_1997` index of concentration. @@ -837,10 +811,6 @@ def ellison_glaeser_egg(x, hs=None): >>> import numpy >>> numpy.random.seed(0) >>> z = numpy.random.randint(10, 50, size=(3,4)) - >>> z - array([[10, 13, 13, 49], - [19, 29, 31, 46], - [33, 16, 34, 34]]) >>> ellison_glaeser_egg(z).round(6) array([0.054499, 0.016242, 0.010141, 0.028803]) @@ -874,6 +844,7 @@ def ellison_glaeser_egg(x, hs=None): return eg_inds +@deprecated_function def ellison_glaeser_egg_pop(x): """ Ellison and Glaeser (1997) :cite:`ellison_1997` index of concentration. @@ -900,12 +871,6 @@ def ellison_glaeser_egg_pop(x): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> y - array([[6, 1, 4], - [4, 8, 4], - [6, 3, 5], - [8, 7, 9]]) - >>> ellison_glaeser_egg_pop(y).round(6) array([-0.021508, 0.013299, -0.038946]) @@ -936,6 +901,7 @@ def ellison_glaeser_egg_pop(x): return eg_inds +@deprecated_function def maurel_sedillot_msg(x, hs=None): """ Maurel and Sedillot (1999) :cite:`maurel_1999` index of concentration. @@ -967,10 +933,6 @@ def maurel_sedillot_msg(x, hs=None): >>> import numpy >>> numpy.random.seed(0) >>> z = numpy.random.randint(10, 50, size=(3,4)) - >>> z - array([[10, 13, 13, 49], - [19, 29, 31, 46], - [33, 16, 34, 34]]) >>> maurel_sedillot_msg(z).round(6) array([ 0.078583, 0.035977, 0.039374, -0.009049]) @@ -1004,6 +966,7 @@ def maurel_sedillot_msg(x, hs=None): return ms_inds +@deprecated_function def maurel_sedillot_msg_pop(x): """ Maurel and Sedillot (1999) :cite:`maurel_1999` index of concentration. @@ -1030,11 +993,6 @@ def maurel_sedillot_msg_pop(x): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> y - array([[6, 1, 4], - [4, 8, 4], - [6, 3, 5], - [8, 7, 9]]) >>> maurel_sedillot_msg_pop(y).round(6) array([-0.055036, 0.044147, -0.028666]) From 4a804af6b4e6f347b0ff007986831be7ab6841ff Mon Sep 17 00:00:00 2001 From: Serge Rey Date: Wed, 14 Aug 2024 15:41:15 -0700 Subject: [PATCH 05/12] Numpy 2.0 doctest adjustments --- inequality/gini.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/inequality/gini.py b/inequality/gini.py index de4f656..95c62d7 100644 --- a/inequality/gini.py +++ b/inequality/gini.py @@ -7,6 +7,7 @@ import numpy from scipy.stats import norm + __all__ = ["Gini", "Gini_Spatial"] @@ -129,13 +130,13 @@ class Gini_Spatial: # noqa N801 >>> numpy.random.seed(12345) >>> gs = Gini_Spatial(y[:,0], w) - >>> gs.p_sim + >>> float(gs.p_sim) 0.04 - >>> gs.wcg + >>> float(gs.wcg) 4353856.0 - >>> gs.e_wcg + >>> float(gs.e_wcg) 4170356.7474747472 Thus, the amount of inequality between pairs of states that are not in the From 640608e6155840ded634322bebc2afa9a55b0f59 Mon Sep 17 00:00:00 2001 From: Serge Rey Date: Wed, 14 Aug 2024 15:54:42 -0700 Subject: [PATCH 06/12] CI: bump codecov action --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 6d65da1..39a6387 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -66,7 +66,7 @@ --doctest-modules - name: codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} file: ./coverage.xml From 087148709086f3bef729d12504cee68b2004b13e Mon Sep 17 00:00:00 2001 From: Serge Rey Date: Wed, 14 Aug 2024 15:59:31 -0700 Subject: [PATCH 07/12] isort --- inequality/_indices.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inequality/_indices.py b/inequality/_indices.py index 81473be..f168f82 100644 --- a/inequality/_indices.py +++ b/inequality/_indices.py @@ -12,11 +12,11 @@ https://www.econstor.eu/bitstream/10419/107568/1/dp8782.pdf """ -import numpy +import functools import itertools import warnings -import functools +import numpy SMALL = numpy.finfo("float").tiny From cf9fd5bfe9b03acda4f1d59716471f9a39c719a6 Mon Sep 17 00:00:00 2001 From: Serge Rey Date: Wed, 14 Aug 2024 16:03:07 -0700 Subject: [PATCH 08/12] isort everything --- inequality/__init__.py | 33 +++++++---------------------- inequality/gini.py | 1 - inequality/tests/test_indices.py | 36 +++++++++----------------------- 3 files changed, 18 insertions(+), 52 deletions(-) diff --git a/inequality/__init__.py b/inequality/__init__.py index 4bafd1e..41b8511 100644 --- a/inequality/__init__.py +++ b/inequality/__init__.py @@ -8,31 +8,14 @@ from importlib.metadata import PackageNotFoundError, version from . import gini, theil -from ._indices import ( - abundance, - ellison_glaeser_egg, - ellison_glaeser_egg_pop, - fractionalization_gs, - gini_gi, - gini_gi_m, - gini_gig, - herfindahl_hd, - hoover_hi, - isolation_ii, - isolation_isg, - margalev_md, - maurel_sedillot_msg, - maurel_sedillot_msg_pop, - menhinick_mi, - modified_segregation_msg, - polarization, - segregation_gsg, - shannon_se, - similarity_w_wd, - simpson_sd, - simpson_so, - theil_th, -) +from ._indices import (abundance, ellison_glaeser_egg, ellison_glaeser_egg_pop, + fractionalization_gs, gini_gi, gini_gi_m, gini_gig, + herfindahl_hd, hoover_hi, isolation_ii, isolation_isg, + margalev_md, maurel_sedillot_msg, + maurel_sedillot_msg_pop, menhinick_mi, + modified_segregation_msg, polarization, segregation_gsg, + shannon_se, similarity_w_wd, simpson_sd, simpson_so, + theil_th) with contextlib.suppress(PackageNotFoundError): __version__ = version("inequality") diff --git a/inequality/gini.py b/inequality/gini.py index 95c62d7..aff0fbe 100644 --- a/inequality/gini.py +++ b/inequality/gini.py @@ -7,7 +7,6 @@ import numpy from scipy.stats import norm - __all__ = ["Gini", "Gini_Spatial"] diff --git a/inequality/tests/test_indices.py b/inequality/tests/test_indices.py index a0f76e7..f9a3c0b 100644 --- a/inequality/tests/test_indices.py +++ b/inequality/tests/test_indices.py @@ -1,32 +1,16 @@ import numpy import pytest -from inequality._indices import ( - abundance, - ellison_glaeser_egg, - ellison_glaeser_egg_pop, - fractionalization_gs, - gini_gi, - gini_gi_m, - gini_gig, - herfindahl_hd, - hoover_hi, - isolation_ii, - isolation_isg, - margalev_md, - maurel_sedillot_msg, - maurel_sedillot_msg_pop, - menhinick_mi, - modified_segregation_msg, - polarization, - segregation_gsg, - shannon_se, - similarity_w_wd, - simpson_sd, - simpson_so, - theil_th, - theil_th_brute, -) +from inequality._indices import (abundance, ellison_glaeser_egg, + ellison_glaeser_egg_pop, fractionalization_gs, + gini_gi, gini_gi_m, gini_gig, herfindahl_hd, + hoover_hi, isolation_ii, isolation_isg, + margalev_md, maurel_sedillot_msg, + maurel_sedillot_msg_pop, menhinick_mi, + modified_segregation_msg, polarization, + segregation_gsg, shannon_se, similarity_w_wd, + simpson_sd, simpson_so, theil_th, + theil_th_brute) x = numpy.array([[0, 1, 2], [0, 2, 4], [0, 0, 3]]) From aeaf7d99b248155f9f00e5b7c55313ecca7526e7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 00:44:09 +0000 Subject: [PATCH 09/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- inequality/_indices.py | 13 +++++++------ inequality/gini.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/inequality/_indices.py b/inequality/_indices.py index f168f82..0a3faa3 100644 --- a/inequality/_indices.py +++ b/inequality/_indices.py @@ -23,14 +23,16 @@ def deprecated_function(func): """Decorator to mark functions as deprecated.""" + @functools.wraps(func) def wrapper(*args, **kwargs): warnings.warn( f"{func.__name__} is deprecated and will be removed on 2025-01-01.", DeprecationWarning, - stacklevel=2 + stacklevel=2, ) return func(*args, **kwargs) + return wrapper @@ -57,7 +59,7 @@ def abundance(x): >>> import numpy >>> x = numpy.array([[0, 1, 2], [0, 2, 4], [0, 0, 3]]) - >>> int(abundance(x)) + >>> int(abundance(x)) 2 """ @@ -123,7 +125,7 @@ def menhinick_mi(x): >>> import numpy >>> x = numpy.array([[0, 1, 2], [0, 2, 4], [0, 0, 3]]) - >>> float(menhinick_mi(x)) + >>> float(menhinick_mi(x)) 0.2886751345948129 """ @@ -510,14 +512,13 @@ def gini_gi_m(x): >>> import numpy >>> numpy.random.seed(0) >>> y = numpy.random.randint(1, 10, size=(4,3)) - >>> float(round(gini_gi_m(y), 10)) + >>> float(round(gini_gi_m(y), 10)) 0.0512820513 """ xs = x.sum(axis=0) - num = numpy.sum([numpy.abs(xi - xj) - for xi, xj in itertools.permutations(xs, 2)]) + num = numpy.sum([numpy.abs(xi - xj) for xi, xj in itertools.permutations(xs, 2)]) den = 2.0 * xs.shape[0] ** 2 * numpy.mean(xs) ggim = num / den return ggim diff --git a/inequality/gini.py b/inequality/gini.py index 95c62d7..03edacb 100644 --- a/inequality/gini.py +++ b/inequality/gini.py @@ -130,7 +130,7 @@ class Gini_Spatial: # noqa N801 >>> numpy.random.seed(12345) >>> gs = Gini_Spatial(y[:,0], w) - >>> float(gs.p_sim) + >>> float(gs.p_sim) 0.04 >>> float(gs.wcg) From ebac9a320a9428cea83172b291b923a6d6603d02 Mon Sep 17 00:00:00 2001 From: Serge Rey Date: Thu, 15 Aug 2024 07:42:33 -0700 Subject: [PATCH 10/12] ruff --- inequality/__init__.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/inequality/__init__.py b/inequality/__init__.py index 41b8511..4bafd1e 100644 --- a/inequality/__init__.py +++ b/inequality/__init__.py @@ -8,14 +8,31 @@ from importlib.metadata import PackageNotFoundError, version from . import gini, theil -from ._indices import (abundance, ellison_glaeser_egg, ellison_glaeser_egg_pop, - fractionalization_gs, gini_gi, gini_gi_m, gini_gig, - herfindahl_hd, hoover_hi, isolation_ii, isolation_isg, - margalev_md, maurel_sedillot_msg, - maurel_sedillot_msg_pop, menhinick_mi, - modified_segregation_msg, polarization, segregation_gsg, - shannon_se, similarity_w_wd, simpson_sd, simpson_so, - theil_th) +from ._indices import ( + abundance, + ellison_glaeser_egg, + ellison_glaeser_egg_pop, + fractionalization_gs, + gini_gi, + gini_gi_m, + gini_gig, + herfindahl_hd, + hoover_hi, + isolation_ii, + isolation_isg, + margalev_md, + maurel_sedillot_msg, + maurel_sedillot_msg_pop, + menhinick_mi, + modified_segregation_msg, + polarization, + segregation_gsg, + shannon_se, + similarity_w_wd, + simpson_sd, + simpson_so, + theil_th, +) with contextlib.suppress(PackageNotFoundError): __version__ = version("inequality") From a55217466d9e4bcd031ac95ffeffc2a8a5ec446d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 15 Aug 2024 14:50:02 +0000 Subject: [PATCH 11/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- inequality/tests/test_indices.py | 36 +++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/inequality/tests/test_indices.py b/inequality/tests/test_indices.py index f9a3c0b..a0f76e7 100644 --- a/inequality/tests/test_indices.py +++ b/inequality/tests/test_indices.py @@ -1,16 +1,32 @@ import numpy import pytest -from inequality._indices import (abundance, ellison_glaeser_egg, - ellison_glaeser_egg_pop, fractionalization_gs, - gini_gi, gini_gi_m, gini_gig, herfindahl_hd, - hoover_hi, isolation_ii, isolation_isg, - margalev_md, maurel_sedillot_msg, - maurel_sedillot_msg_pop, menhinick_mi, - modified_segregation_msg, polarization, - segregation_gsg, shannon_se, similarity_w_wd, - simpson_sd, simpson_so, theil_th, - theil_th_brute) +from inequality._indices import ( + abundance, + ellison_glaeser_egg, + ellison_glaeser_egg_pop, + fractionalization_gs, + gini_gi, + gini_gi_m, + gini_gig, + herfindahl_hd, + hoover_hi, + isolation_ii, + isolation_isg, + margalev_md, + maurel_sedillot_msg, + maurel_sedillot_msg_pop, + menhinick_mi, + modified_segregation_msg, + polarization, + segregation_gsg, + shannon_se, + similarity_w_wd, + simpson_sd, + simpson_so, + theil_th, + theil_th_brute, +) x = numpy.array([[0, 1, 2], [0, 2, 4], [0, 0, 3]]) From e155294ccf6e22398d2b7d8621e9379723b0b7ab Mon Sep 17 00:00:00 2001 From: Serge Rey Date: Thu, 15 Aug 2024 07:52:54 -0700 Subject: [PATCH 12/12] FutureWarnings for indices --- inequality/_indices.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inequality/_indices.py b/inequality/_indices.py index 0a3faa3..7fb366a 100644 --- a/inequality/_indices.py +++ b/inequality/_indices.py @@ -28,7 +28,7 @@ def deprecated_function(func): def wrapper(*args, **kwargs): warnings.warn( f"{func.__name__} is deprecated and will be removed on 2025-01-01.", - DeprecationWarning, + FutureWarning, stacklevel=2, ) return func(*args, **kwargs)