Skip to content

Commit

Permalink
Merge pull request #88 from sjsrey/gini-polarization
Browse files Browse the repository at this point in the history
Polarization indices and new documentation
  • Loading branch information
sjsrey authored Jan 3, 2025
2 parents 6d702d5 + cdc9470 commit cb10912
Show file tree
Hide file tree
Showing 33 changed files with 3,997 additions and 1,850 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Contribute

PySAL-inequality is under active development and contributors are welcome.

Please see the [Contributing](contributing.md) instructions.

If you have any suggestion, feature request, or bug report, please open a new [issue](https://github.com/pysal/inequality/issues) on GitHub. To submit patches, please follow the PySAL development [guidelines](http://pysal.org/docs/devs/) and open a [pull request](https://github.com/pysal/inequality). Once your changes get merged, you’ll automatically be added to the [Contributors List](https://github.com/pysal/inequality/graphs/contributors).

Support
Expand Down
17 changes: 11 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@

import pytest


def warning_depr(x):
return pytest.warns(
FutureWarning, match=f"{x} is deprecated and will be removed on 2025-01-01."
FutureWarning,
match=f"{x} is deprecated and will be removed on 2025-01-01."
)


def warning_invalid(x):
return pytest.warns(RuntimeWarning, match=f"invalid value encountered in {x}")
return pytest.warns(RuntimeWarning,
match=f"invalid value encountered in {x}")

warning_div_zero = pytest.warns(RuntimeWarning, match="divide by zero encountered")

warning_div_zero = pytest.warns(RuntimeWarning,
match="divide by zero encountered")

def pytest_configure(config):

def pytest_configure():
pytest.warning_depr = warning_depr
pytest.warning_invalid = warning_invalid
pytest.warning_div_zero = warning_div_zero


def pytest_ignore_collect(collection_path):
return True if str(collection_path).endswith("_indices.py") else False

return bool(str(collection_path).endswith("_indices.py"))
84 changes: 84 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Contributing to inequality

Contributions to inequality are much appreciated.

## Steps to Contribute

1. Fork the inequality git repository
2. Create a development environment
3. Activate the new environment
4. Install project dependencies
5. Verify installation and run tests
6. Build documentation
7. Submitting a Pull Request

## 1. Fork the inequality git repository

- On github, fork the repository at: <https://github.com/pysal/inequality>
- From your new fork, grab the clone url:
```
git clone [email protected]:your-user-name/inequality.git inequality-yourname
cd inequality-yourname
git remote add upstream git://github.com/pysal/inequality.git
```

## 2. Create a development environment

- Install either [Anaconda](http://docs.continuum.io/anaconda/) or [miniconda](http://conda.pydata.org/miniconda.html)
- `cd` into the `inequality-yourname` source directory that you cloned in step 1

```
conda create --name inequality python=3.10
```

## 3. Activate the new environment
```
conda activate inequality
```
## 4. Install project dependencies
```
pip install .[dev,docs,tests]
```

Note, if you are on zsh use:

```
pip install '.[dev,docs,tests]'
```
If this fails on MacOS you have to have `proj` installed:
```
brew install proj
```

Set this variable in your shell configuration (e.g., ~/.zshrc or ~/.bashrc):
```
export PROJ_DIR="/opt/homebrew/opt/proj"
```
Then, reload your shell configuration:
```
source ~/.zshrc
```
and check that `proj` is correctly installed:
```
proj
```

## 5. Verify installation and run tests
```
python -c "import libpysal; print('libpysal version:', libpysal.__version__)"
pytest inequality
```


## 6. Build documentation
```
cd docs
make html
```

## 7. Submitting a Pull Request

If you have made changes that you have pushed to your forked repository, you can
submit a pull request to have them integrated into the `inequality` code base.

See the [GitHUB tutorial](https://help.github.com/articles/using-pull-requests/).
15 changes: 13 additions & 2 deletions docs/_static/auto/references.el
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
;; -*- lexical-binding: t; -*-

(TeX-add-style-hook
"references"
(lambda ()
(LaTeX-add-bibitems
"hoffmann2024MeasuringMismeasuring"
"wolfson1994WhenInequalities"
"schutz1951MeasurementIncome"
"Atkinson_1970_Measurement"
"care_2012"
"ellison_1997"
"maurel_1999"
"nijkamp2015cultural"
"rey_interregional_2010"
"rey_comparative_2015"
"Rey_2013_sea"))
:bibtex)
"Rey_2013_sea"
"van_Mourik_1989"))
'(or :bibtex :latex))

30 changes: 30 additions & 0 deletions docs/_static/references.bib
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@

@misc{hoffmann2024MeasuringMismeasuring,
title = {Measuring and {{Mismeasuring Income Polarization}}},
author = {Hoffmann, Rodolfo and Kassouf, Ana Lucia},
year = {2024},
month = mar,
doi = {10.21203/rs.3.rs-4139220/v1},
urldate = {2024-08-12},
abstract = {The main contribution of this paper is to clarify some of the misconceptions about income polarization indices observed in the existing literature. Our analysis explores the domain of measures of polarization of the income distribution, with a specific emphasis on elucidating the importance of distinguishing between bipolarization and multipolarization measures. Additionally, we assert that a valid polarization metric must adhere to the principle of scale-invariance. Furthermore, in cases where the income distribution is categorized into relatively poor and relatively rich, a valid bipolarization measure should consistently increase when regressive transfers occur from poorer to richer individuals and when progressive transfers occur between two poorer or two richer individuals. The study identifies instances where bipolarization measures that fail to adhere to these criteria have been employed in previous research, leading to erroneous conclusions. The research also provides a succinct analysis of the challenges faced by scholars in employing Esteban and Ray's multipolarization measure and its adapted versions. Artificial numerical examples are used to illustrate the application of different polarization measures in various scenarios. Additionally, a real-world illustration is presented that depicts a declining trend of the bipolarization of income distribution in Brazil from 2001 to 2015, coinciding with a decrease in inequality during this period. The study concludes by pinpointing errors in previously published works.},
copyright = {https://creativecommons.org/licenses/by/4.0/},
langid = {english},
file = {/home/serge/Zotero/storage/WM4696MT/Hoffmann and Kassouf - 2024 - Measuring and Mismeasuring Income Polarization.pdf}
}

@article{wolfson1994WhenInequalities,
title = {When {{Inequalities Diverge}}},
author = {Wolfson, Michael C.},
year = {1994},
journal = {The American Economic Review},
volume = {84},
number = {2},
eprint = {2117858},
eprinttype = {jstor},
pages = {353--358},
publisher = {American Economic Association},
issn = {0002-8282},
urldate = {2024-08-12},
file = {/home/serge/Zotero/storage/8JYHLHTW/Wolfson - 1994 - When Inequalities Diverge.pdf}
}

@article{schutz1951MeasurementIncome,
title = {On the {{Measurement}} of {{Income Inequality}}},
author = {Schutz, Robert R.},
Expand Down
32 changes: 19 additions & 13 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,56 @@ API reference

.. _inequality_api:


Atkinson Inequality Measures
----------------------------

.. autosummary::
:toctree: generated/

inequality.atkinson.Atkinson

atkinson.Atkinson


Gini Inequality Measures
------------------------

.. autosummary::
:toctree: generated/

inequality.gini.Gini
inequality.gini.Gini_Spatial
gini.Gini
gini.Gini_Spatial

Schutz Inequality Measures
--------------------------

.. autosummary::
:toctree: generated/

inequality.schutz.Schutz


schutz.Schutz

Theil Inequality Measures
-------------------------

.. autosummary::
:toctree: generated/

inequality.theil.Theil
inequality.theil.TheilD
inequality.theil.TheilDSim
theil.Theil
theil.TheilD
theil.TheilDSim

Wolfson Bipolarization Measure
------------------------------
.. autosummary::
:toctree: generated/

wolfson.wolfson


Pengram
-------

.. autosummary::
:toctree: generated/

inequality.pen.pen
inequality.pen.pengram
pen.pen
pen.pengram

26 changes: 14 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#

import sphinx_bootstrap_theme

from datetime import datetime

# import your package to obtain the version info to display on the docs website
import inequality
import sphinx_bootstrap_theme

# -- General configuration ------------------------------------------------

Expand All @@ -31,7 +31,7 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [ #'sphinx_gallery.gen_gallery',
extensions = [ # 'sphinx_gallery.gen_gallery',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.viewcode",
Expand Down Expand Up @@ -60,7 +60,7 @@

# General information about the project.
project = "inequality" # string of your project name, for example, 'giddy'
copyright = "2018, pysal developers"
copyright = f"2018 - {datetime.now().year}, pysal developers (BSD License)"
author = "pysal developers"

# The version info for the project you're documenting, acts as replacement for
Expand Down Expand Up @@ -95,8 +95,9 @@
# a list of builtin themes.
#
# html_theme = 'alabaster'
html_theme = "bootstrap"
html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
# html_theme = "bootstrap"
html_theme = "pydata_sphinx_theme"
# html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
html_title = "%s v%s Manual" % (project, version)

# (Optional) Logo of your package. Should be small enough to fit the navbar (ideally 24x24).
Expand All @@ -105,7 +106,8 @@

# (Optional) PySAL favicon
html_favicon = "_static/images/pysal_favicon.ico"

html_logo = "_static/images/pysal_logo.png"
icon_links_label = "inequality"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -117,12 +119,12 @@
# Render the next and previous page links in navbar. (Default: true)
"navbar_sidebarrel": False,
# Render the current pages TOC in the navbar. (Default: true)
#'navbar_pagenav': True,
#'navbar_pagenav': False,
# 'navbar_pagenav': True,
# 'navbar_pagenav': False,
# No sidebar
"nosidebar": True,
# Tab name for the current pages TOC. (Default: "Page")
#'navbar_pagenav_name': "Page",
# 'navbar_pagenav_name': "Page",
# Global TOC depth for "site" navbar tab. (Default: 1)
# Switching to -1 shows all levels.
"globaltoc_depth": 2,
Expand All @@ -136,7 +138,7 @@
"globaltoc_includehidden": "true",
# HTML navbar class (Default: "navbar") to attach to <div> element.
# For black navbar, do "navbar navbar-inverse"
#'navbar_class': "navbar navbar-inverse",
# 'navbar_class': "navbar navbar-inverse",
# Fix navigation bar to top of page?
# Values: "true" (default) or "false"
"navbar_fixed_top": "true",
Expand All @@ -154,7 +156,7 @@
# Navigation bar menu
"navbar_links": [
("Installation", "installation"),
("Tutorials", "tutorials"),
("User Guide", "user-guide/intro"),
("API", "api"),
("References", "references"),
],
Expand Down
15 changes: 10 additions & 5 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,19 @@ software, terms & conditions for usage, and a DISCLAIMER OF ALL
WARRANTIES.


inequality
==========

Documentation contents
----------------------

.. toctree::
:hidden:
:maxdepth: 4
:caption: Contents:
:maxdepth: 1

Home <self>
Installation <installation>
Tutorials <tutorials>
API <api>
API reference <api>
user-guide/intro
References <references>

.. _PySAL: https://github.com/pysal/pysal
Expand Down
11 changes: 0 additions & 11 deletions docs/tutorials.rst

This file was deleted.

12 changes: 12 additions & 0 deletions docs/user-guide/intro.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
==========
User Guide
==========

This user guide covers essential features of pysal-inequality, mostly in the form of interactive Jupyter notebooks. Reading this guide, you will learn:

- how to :ref:`visualize <viz>` spatial inequality
- how to :ref:`measure <measure>` spatial inequality

Notebooks cover just a small selection of functions as an illustration of
principles. For a full overview of pysal-inequality capabilities, head to the `API <../api.rst>`_.

Loading

0 comments on commit cb10912

Please sign in to comment.