microdf-python 0.4.5__tar.gz → 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. microdf_python-1.0.0/PKG-INFO +75 -0
  2. microdf_python-1.0.0/README.md +49 -0
  3. microdf_python-1.0.0/microdf/__init__.py +14 -0
  4. {microdf_python-0.4.5 → microdf_python-1.0.0}/microdf/tests/test_microseries_dataframe.py +0 -18
  5. microdf_python-1.0.0/microdf_python.egg-info/PKG-INFO +75 -0
  6. microdf_python-1.0.0/microdf_python.egg-info/SOURCES.txt +13 -0
  7. {microdf_python-0.4.5 → microdf_python-1.0.0}/microdf_python.egg-info/requires.txt +0 -4
  8. {microdf_python-0.4.5 → microdf_python-1.0.0}/pyproject.toml +3 -7
  9. microdf_python-0.4.5/PKG-INFO +0 -47
  10. microdf_python-0.4.5/README.md +0 -18
  11. microdf_python-0.4.5/microdf/__init__.py +0 -160
  12. microdf_python-0.4.5/microdf/_optional.py +0 -85
  13. microdf_python-0.4.5/microdf/agg.py +0 -90
  14. microdf_python-0.4.5/microdf/concat.py +0 -29
  15. microdf_python-0.4.5/microdf/constants.py +0 -40
  16. microdf_python-0.4.5/microdf/custom_taxes.py +0 -174
  17. microdf_python-0.4.5/microdf/income_measures.py +0 -63
  18. microdf_python-0.4.5/microdf/inequality.py +0 -219
  19. microdf_python-0.4.5/microdf/io.py +0 -30
  20. microdf_python-0.4.5/microdf/poverty.py +0 -136
  21. microdf_python-0.4.5/microdf/tax.py +0 -78
  22. microdf_python-0.4.5/microdf/taxcalc.py +0 -161
  23. microdf_python-0.4.5/microdf/tests/test_compare.py +0 -48
  24. microdf_python-0.4.5/microdf/tests/test_decile_rank.py +0 -91
  25. microdf_python-0.4.5/microdf/tests/test_inequality.py +0 -20
  26. microdf_python-0.4.5/microdf/tests/test_io.py +0 -10
  27. microdf_python-0.4.5/microdf/tests/test_optional_dependency.py +0 -54
  28. microdf_python-0.4.5/microdf/tests/test_poverty.py +0 -73
  29. microdf_python-0.4.5/microdf/tests/test_quantile_chg.py +0 -14
  30. microdf_python-0.4.5/microdf/tests/test_tax.py +0 -54
  31. microdf_python-0.4.5/microdf/tests/test_taxcalc.py +0 -25
  32. microdf_python-0.4.5/microdf/tests/test_utils.py +0 -39
  33. microdf_python-0.4.5/microdf/tests/test_weighted.py +0 -74
  34. microdf_python-0.4.5/microdf/ubi.py +0 -46
  35. microdf_python-0.4.5/microdf/utils.py +0 -73
  36. microdf_python-0.4.5/microdf/weighted.py +0 -235
  37. microdf_python-0.4.5/microdf_python.egg-info/PKG-INFO +0 -47
  38. microdf_python-0.4.5/microdf_python.egg-info/SOURCES.txt +0 -38
  39. {microdf_python-0.4.5 → microdf_python-1.0.0}/LICENSE +0 -0
  40. {microdf_python-0.4.5 → microdf_python-1.0.0}/microdf/microdataframe.py +0 -0
  41. {microdf_python-0.4.5 → microdf_python-1.0.0}/microdf/microseries.py +0 -0
  42. {microdf_python-0.4.5 → microdf_python-1.0.0}/microdf/tests/conftest.py +0 -0
  43. {microdf_python-0.4.5 → microdf_python-1.0.0}/microdf_python.egg-info/dependency_links.txt +0 -0
  44. {microdf_python-0.4.5 → microdf_python-1.0.0}/microdf_python.egg-info/top_level.txt +0 -0
  45. {microdf_python-0.4.5 → microdf_python-1.0.0}/setup.cfg +0 -0
@@ -0,0 +1,75 @@
1
+ Metadata-Version: 2.4
2
+ Name: microdf-python
3
+ Version: 1.0.0
4
+ Summary: Weighted pandas DataFrames and Series for survey microdata
5
+ Author-email: Max Ghenis <max@ubicenter.org>
6
+ License: MIT
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: numpy
11
+ Requires-Dist: pandas
12
+ Provides-Extra: dev
13
+ Requires-Dist: codecov; extra == "dev"
14
+ Requires-Dist: flake8; extra == "dev"
15
+ Requires-Dist: flake8-pyproject; extra == "dev"
16
+ Requires-Dist: black; extra == "dev"
17
+ Requires-Dist: docformatter; extra == "dev"
18
+ Requires-Dist: isort; extra == "dev"
19
+ Requires-Dist: linecheck; extra == "dev"
20
+ Requires-Dist: pytest; extra == "dev"
21
+ Requires-Dist: pytest-cov; extra == "dev"
22
+ Requires-Dist: setuptools; extra == "dev"
23
+ Provides-Extra: docs
24
+ Requires-Dist: jupyter_book; extra == "docs"
25
+ Dynamic: license-file
26
+
27
+ [![Build](https://github.com/PolicyEngine/microdf/workflows/Pull%20request/badge.svg)](https://github.com/PolicyEngine/microdf/actions)
28
+ [![Codecov](https://codecov.io/gh/PolicyEngine/microdf/branch/master/graph/badge.svg)](https://codecov.io/gh/PolicyEngine/microdf)
29
+
30
+ # microdf
31
+ Weighted pandas DataFrames and Series for survey microdata analysis.
32
+
33
+ ## Overview
34
+ microdf provides `MicroDataFrame` and `MicroSeries` classes that extend pandas functionality with integrated weighting support, essential for accurate survey data analysis.
35
+
36
+ ## Key Features
37
+ - **MicroDataFrame**: A pandas DataFrame with an integrated weight column
38
+ - **MicroSeries**: A pandas Series with integrated weights
39
+ - **Weighted operations**: All aggregations (sum, mean, median, etc.) automatically use weights
40
+ - **Inequality metrics**: Built-in Gini coefficient calculation
41
+ - **Poverty analysis**: Integrated poverty rate and gap calculations
42
+
43
+ ## Installation
44
+ Install with:
45
+
46
+ pip install microdf-python
47
+
48
+ Or for development:
49
+
50
+ pip install git+https://github.com/PolicyEngine/microdf.git
51
+
52
+ ## Usage
53
+ ```python
54
+ import microdf as mdf
55
+ import pandas as pd
56
+
57
+ # Create sample data with weights
58
+ df = pd.DataFrame({
59
+ 'income': [10_000, 20_000, 30_000, 40_000, 50_000],
60
+ 'weights': [1, 2, 3, 2, 1]
61
+ })
62
+
63
+ # Create a MicroDataFrame
64
+ mdf_df = mdf.MicroDataFrame(df, weights='weights')
65
+
66
+ # All operations are weight-aware
67
+ print(mdf_df.income.mean()) # Weighted mean
68
+ print(mdf_df.income.gini()) # Gini coefficient
69
+ ```
70
+
71
+ ## Questions
72
+ Contact the maintainer, Max Ghenis (max@policyengine.org).
73
+
74
+ ## Citation
75
+ You may cite the source of your analysis as "microdf release #.#.#, author's calculations."
@@ -0,0 +1,49 @@
1
+ [![Build](https://github.com/PolicyEngine/microdf/workflows/Pull%20request/badge.svg)](https://github.com/PolicyEngine/microdf/actions)
2
+ [![Codecov](https://codecov.io/gh/PolicyEngine/microdf/branch/master/graph/badge.svg)](https://codecov.io/gh/PolicyEngine/microdf)
3
+
4
+ # microdf
5
+ Weighted pandas DataFrames and Series for survey microdata analysis.
6
+
7
+ ## Overview
8
+ microdf provides `MicroDataFrame` and `MicroSeries` classes that extend pandas functionality with integrated weighting support, essential for accurate survey data analysis.
9
+
10
+ ## Key Features
11
+ - **MicroDataFrame**: A pandas DataFrame with an integrated weight column
12
+ - **MicroSeries**: A pandas Series with integrated weights
13
+ - **Weighted operations**: All aggregations (sum, mean, median, etc.) automatically use weights
14
+ - **Inequality metrics**: Built-in Gini coefficient calculation
15
+ - **Poverty analysis**: Integrated poverty rate and gap calculations
16
+
17
+ ## Installation
18
+ Install with:
19
+
20
+ pip install microdf-python
21
+
22
+ Or for development:
23
+
24
+ pip install git+https://github.com/PolicyEngine/microdf.git
25
+
26
+ ## Usage
27
+ ```python
28
+ import microdf as mdf
29
+ import pandas as pd
30
+
31
+ # Create sample data with weights
32
+ df = pd.DataFrame({
33
+ 'income': [10_000, 20_000, 30_000, 40_000, 50_000],
34
+ 'weights': [1, 2, 3, 2, 1]
35
+ })
36
+
37
+ # Create a MicroDataFrame
38
+ mdf_df = mdf.MicroDataFrame(df, weights='weights')
39
+
40
+ # All operations are weight-aware
41
+ print(mdf_df.income.mean()) # Weighted mean
42
+ print(mdf_df.income.gini()) # Gini coefficient
43
+ ```
44
+
45
+ ## Questions
46
+ Contact the maintainer, Max Ghenis (max@policyengine.org).
47
+
48
+ ## Citation
49
+ You may cite the source of your analysis as "microdf release #.#.#, author's calculations."
@@ -0,0 +1,14 @@
1
+ from .microdataframe import MicroDataFrame, MicroDataFrameGroupBy
2
+ from .microseries import MicroSeries, MicroSeriesGroupBy
3
+
4
+ name = "microdf"
5
+ __version__ = "0.1.0"
6
+
7
+ __all__ = [
8
+ # microseries.py
9
+ "MicroSeries",
10
+ "MicroSeriesGroupBy",
11
+ # microdataframe.py
12
+ "MicroDataFrame",
13
+ "MicroDataFrameGroupBy",
14
+ ]
@@ -105,24 +105,6 @@ def test_multiple_groupby() -> None:
105
105
  assert (df.groupby(["x", "y"]).z.sum() == np.array([5, 6])).all()
106
106
 
107
107
 
108
- def test_concat() -> None:
109
- df1 = mdf.MicroDataFrame({"x": [1, 2]}, weights=[3, 4])
110
- df2 = mdf.MicroDataFrame({"y": [5, 6]}, weights=[7, 8])
111
- # Verify that pd.concat returns DataFrame (probably no way to fix this).
112
- pd_long = pd.concat([df1, df2])
113
- assert isinstance(pd_long, pd.DataFrame)
114
- assert not isinstance(pd_long, mdf.MicroDataFrame)
115
- # Verify that mdf.concat works.
116
- mdf_long = mdf.concat([df1, df2])
117
- assert isinstance(mdf_long, mdf.MicroDataFrame)
118
- # Weights should be preserved.
119
- assert mdf_long.weights.equals(pd.concat([df1.weights, df2.weights]))
120
- # Verify it works horizontally too (take the first set of weights).
121
- mdf_wide = mdf.concat([df1, df2], axis=1)
122
- assert isinstance(mdf_wide, mdf.MicroDataFrame)
123
- assert mdf_wide.weights.equals(df1.weights)
124
-
125
-
126
108
  def test_set_index() -> None:
127
109
  d = mdf.MicroDataFrame(dict(x=[1, 2, 3]), weights=[4, 5, 6])
128
110
  assert d.x.__class__ == MicroSeries
@@ -0,0 +1,75 @@
1
+ Metadata-Version: 2.4
2
+ Name: microdf-python
3
+ Version: 1.0.0
4
+ Summary: Weighted pandas DataFrames and Series for survey microdata
5
+ Author-email: Max Ghenis <max@ubicenter.org>
6
+ License: MIT
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: numpy
11
+ Requires-Dist: pandas
12
+ Provides-Extra: dev
13
+ Requires-Dist: codecov; extra == "dev"
14
+ Requires-Dist: flake8; extra == "dev"
15
+ Requires-Dist: flake8-pyproject; extra == "dev"
16
+ Requires-Dist: black; extra == "dev"
17
+ Requires-Dist: docformatter; extra == "dev"
18
+ Requires-Dist: isort; extra == "dev"
19
+ Requires-Dist: linecheck; extra == "dev"
20
+ Requires-Dist: pytest; extra == "dev"
21
+ Requires-Dist: pytest-cov; extra == "dev"
22
+ Requires-Dist: setuptools; extra == "dev"
23
+ Provides-Extra: docs
24
+ Requires-Dist: jupyter_book; extra == "docs"
25
+ Dynamic: license-file
26
+
27
+ [![Build](https://github.com/PolicyEngine/microdf/workflows/Pull%20request/badge.svg)](https://github.com/PolicyEngine/microdf/actions)
28
+ [![Codecov](https://codecov.io/gh/PolicyEngine/microdf/branch/master/graph/badge.svg)](https://codecov.io/gh/PolicyEngine/microdf)
29
+
30
+ # microdf
31
+ Weighted pandas DataFrames and Series for survey microdata analysis.
32
+
33
+ ## Overview
34
+ microdf provides `MicroDataFrame` and `MicroSeries` classes that extend pandas functionality with integrated weighting support, essential for accurate survey data analysis.
35
+
36
+ ## Key Features
37
+ - **MicroDataFrame**: A pandas DataFrame with an integrated weight column
38
+ - **MicroSeries**: A pandas Series with integrated weights
39
+ - **Weighted operations**: All aggregations (sum, mean, median, etc.) automatically use weights
40
+ - **Inequality metrics**: Built-in Gini coefficient calculation
41
+ - **Poverty analysis**: Integrated poverty rate and gap calculations
42
+
43
+ ## Installation
44
+ Install with:
45
+
46
+ pip install microdf-python
47
+
48
+ Or for development:
49
+
50
+ pip install git+https://github.com/PolicyEngine/microdf.git
51
+
52
+ ## Usage
53
+ ```python
54
+ import microdf as mdf
55
+ import pandas as pd
56
+
57
+ # Create sample data with weights
58
+ df = pd.DataFrame({
59
+ 'income': [10_000, 20_000, 30_000, 40_000, 50_000],
60
+ 'weights': [1, 2, 3, 2, 1]
61
+ })
62
+
63
+ # Create a MicroDataFrame
64
+ mdf_df = mdf.MicroDataFrame(df, weights='weights')
65
+
66
+ # All operations are weight-aware
67
+ print(mdf_df.income.mean()) # Weighted mean
68
+ print(mdf_df.income.gini()) # Gini coefficient
69
+ ```
70
+
71
+ ## Questions
72
+ Contact the maintainer, Max Ghenis (max@policyengine.org).
73
+
74
+ ## Citation
75
+ You may cite the source of your analysis as "microdf release #.#.#, author's calculations."
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ microdf/__init__.py
5
+ microdf/microdataframe.py
6
+ microdf/microseries.py
7
+ microdf/tests/conftest.py
8
+ microdf/tests/test_microseries_dataframe.py
9
+ microdf_python.egg-info/PKG-INFO
10
+ microdf_python.egg-info/SOURCES.txt
11
+ microdf_python.egg-info/dependency_links.txt
12
+ microdf_python.egg-info/requires.txt
13
+ microdf_python.egg-info/top_level.txt
@@ -9,13 +9,9 @@ black
9
9
  docformatter
10
10
  isort
11
11
  linecheck
12
- pip
13
12
  pytest
14
13
  pytest-cov
15
14
  setuptools
16
15
 
17
16
  [docs]
18
17
  jupyter_book
19
-
20
- [taxcalc]
21
- taxcalc
@@ -4,8 +4,8 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "microdf-python"
7
- version = "0.4.5"
8
- description = "Survey microdata as DataFrames"
7
+ version = "1.0.0"
8
+ description = "Weighted pandas DataFrames and Series for survey microdata"
9
9
  readme = "README.md"
10
10
  authors = [
11
11
  { name = "Max Ghenis", email = "max@ubicenter.org" }
@@ -26,7 +26,6 @@ dev = [
26
26
  "docformatter",
27
27
  "isort",
28
28
  "linecheck",
29
- "pip",
30
29
  "pytest",
31
30
  "pytest-cov",
32
31
  "setuptools",
@@ -34,9 +33,6 @@ dev = [
34
33
  docs = [
35
34
  "jupyter_book",
36
35
  ]
37
- taxcalc = [
38
- "taxcalc",
39
- ]
40
36
 
41
37
  [tool.setuptools.packages.find]
42
38
  where = ["."]
@@ -48,7 +44,7 @@ line_length = 79
48
44
 
49
45
  [tool.black]
50
46
  line-length = 79
51
- target-version = ["py311"]
47
+ target-version = ["py313"]
52
48
 
53
49
  [tool.flake8]
54
50
  max-line-length = 79
@@ -1,47 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: microdf-python
3
- Version: 0.4.5
4
- Summary: Survey microdata as DataFrames
5
- Author-email: Max Ghenis <max@ubicenter.org>
6
- License: MIT
7
- Requires-Python: >=3.9
8
- Description-Content-Type: text/markdown
9
- License-File: LICENSE
10
- Requires-Dist: numpy
11
- Requires-Dist: pandas
12
- Provides-Extra: dev
13
- Requires-Dist: codecov; extra == "dev"
14
- Requires-Dist: flake8; extra == "dev"
15
- Requires-Dist: flake8-pyproject; extra == "dev"
16
- Requires-Dist: black; extra == "dev"
17
- Requires-Dist: docformatter; extra == "dev"
18
- Requires-Dist: isort; extra == "dev"
19
- Requires-Dist: linecheck; extra == "dev"
20
- Requires-Dist: pip; extra == "dev"
21
- Requires-Dist: pytest; extra == "dev"
22
- Requires-Dist: pytest-cov; extra == "dev"
23
- Requires-Dist: setuptools; extra == "dev"
24
- Provides-Extra: docs
25
- Requires-Dist: jupyter_book; extra == "docs"
26
- Provides-Extra: taxcalc
27
- Requires-Dist: taxcalc; extra == "taxcalc"
28
- Dynamic: license-file
29
-
30
- [![Build](https://github.com/PSLmodels/microdf/workflows/Build%20and%20test%20[Python%203.7,%203.8,%203.9]/badge.svg)](https://github.com/PSLmodels/microdf/actions?query=workflow%3A%22Build+and+test+%5BPython+3.7%2C+3.8%2C+3.9%5D%22)
31
- [![Codecov](https://codecov.io/gh/PSLmodels/microdf/branch/master/graph/badge.svg)](https://codecov.io/gh/PSLmodels/microdf)
32
-
33
- # microdf
34
- Analysis tools for working with survey microdata as DataFrames.
35
-
36
- *Disclaimer: `MicroSeries` and `MicroDataFrame` are experimental features and may not consider weights after performing some operations. See open issues.*
37
-
38
- ## Installation
39
- Install with:
40
-
41
- pip install git+git://github.com/PSLmodels/microdf.git
42
-
43
- ## Questions
44
- Contact the maintainer, Max Ghenis (mghenis@gmail.com).
45
-
46
- ## Citation
47
- You may cite the source of your analysis as "microdf release #.#.#, author's calculations."
@@ -1,18 +0,0 @@
1
- [![Build](https://github.com/PSLmodels/microdf/workflows/Build%20and%20test%20[Python%203.7,%203.8,%203.9]/badge.svg)](https://github.com/PSLmodels/microdf/actions?query=workflow%3A%22Build+and+test+%5BPython+3.7%2C+3.8%2C+3.9%5D%22)
2
- [![Codecov](https://codecov.io/gh/PSLmodels/microdf/branch/master/graph/badge.svg)](https://codecov.io/gh/PSLmodels/microdf)
3
-
4
- # microdf
5
- Analysis tools for working with survey microdata as DataFrames.
6
-
7
- *Disclaimer: `MicroSeries` and `MicroDataFrame` are experimental features and may not consider weights after performing some operations. See open issues.*
8
-
9
- ## Installation
10
- Install with:
11
-
12
- pip install git+git://github.com/PSLmodels/microdf.git
13
-
14
- ## Questions
15
- Contact the maintainer, Max Ghenis (mghenis@gmail.com).
16
-
17
- ## Citation
18
- You may cite the source of your analysis as "microdf release #.#.#, author's calculations."
@@ -1,160 +0,0 @@
1
- from .agg import agg, combine_base_reform, pctchg_base_reform
2
- from .concat import concat
3
- from .constants import (
4
- BENS,
5
- ECI_REMOVE_COLS,
6
- HOUSING_CASH_SHARE,
7
- MCAID_CASH_SHARE,
8
- MCARE_CASH_SHARE,
9
- MED_BENS,
10
- OTHER_CASH_SHARE,
11
- SNAP_CASH_SHARE,
12
- SSI_CASH_SHARE,
13
- TANF_CASH_SHARE,
14
- VET_CASH_SHARE,
15
- WIC_CASH_SHARE,
16
- )
17
- from .custom_taxes import (
18
- CARBON_TAX_INCIDENCE,
19
- FTT_INCIDENCE,
20
- VAT_INCIDENCE,
21
- add_carbon_tax,
22
- add_custom_tax,
23
- add_ftt,
24
- add_vat,
25
- )
26
- from .income_measures import cash_income, market_income, tpc_eci
27
- from .inequality import (
28
- bottom_50_pct_share,
29
- bottom_x_pct_share,
30
- gini,
31
- t10_b50,
32
- top_0_1_pct_share,
33
- top_1_pct_share,
34
- top_10_pct_share,
35
- top_50_pct_share,
36
- top_x_pct_share,
37
- )
38
- from .io import read_stata_zip
39
- from .microdataframe import MicroDataFrame, MicroDataFrameGroupBy
40
- from .microseries import MicroSeries, MicroSeriesGroupBy
41
- from .poverty import (
42
- deep_poverty_gap,
43
- deep_poverty_rate,
44
- fpl,
45
- poverty_gap,
46
- poverty_rate,
47
- squared_poverty_gap,
48
- )
49
- from .tax import mtr, tax_from_mtrs
50
- from .taxcalc import (
51
- add_weighted_metrics,
52
- calc_df,
53
- n65,
54
- recalculate,
55
- static_baseline_calc,
56
- )
57
- from .ubi import ubi_or_bens
58
- from .utils import (
59
- cartesian_product,
60
- dedup_list,
61
- flatten,
62
- listify,
63
- ordinal_label,
64
- )
65
- from .weighted import (
66
- add_weighted_quantiles,
67
- quantile_chg,
68
- weight,
69
- weighted_mean,
70
- weighted_median,
71
- weighted_quantile,
72
- weighted_sum,
73
- )
74
-
75
- name = "microdf"
76
- __version__ = "0.1.0"
77
-
78
- __all__ = [
79
- # agg.py
80
- "combine_base_reform",
81
- "pctchg_base_reform",
82
- "agg",
83
- # concat.py
84
- "concat",
85
- # constants.py
86
- "BENS",
87
- "ECI_REMOVE_COLS",
88
- "HOUSING_CASH_SHARE",
89
- "MCAID_CASH_SHARE",
90
- "MCARE_CASH_SHARE",
91
- "MED_BENS",
92
- "OTHER_CASH_SHARE",
93
- "SNAP_CASH_SHARE",
94
- "SSI_CASH_SHARE",
95
- "TANF_CASH_SHARE",
96
- "VET_CASH_SHARE",
97
- "WIC_CASH_SHARE",
98
- # custom_taxes.py
99
- "CARBON_TAX_INCIDENCE",
100
- "FTT_INCIDENCE",
101
- "VAT_INCIDENCE",
102
- "add_custom_tax",
103
- "add_vat",
104
- "add_carbon_tax",
105
- "add_ftt",
106
- # income_measures.py
107
- "cash_income",
108
- "tpc_eci",
109
- "market_income",
110
- # inequality.py
111
- "gini",
112
- "top_x_pct_share",
113
- "bottom_x_pct_share",
114
- "bottom_50_pct_share",
115
- "top_10_pct_share",
116
- "top_1_pct_share",
117
- "top_0_1_pct_share",
118
- "top_50_pct_share",
119
- "t10_b50",
120
- # io.py
121
- "read_stata_zip",
122
- # poverty.py
123
- "fpl",
124
- "poverty_rate",
125
- "deep_poverty_rate",
126
- "poverty_gap",
127
- "squared_poverty_gap",
128
- "deep_poverty_gap",
129
- # tax.py
130
- "mtr",
131
- "tax_from_mtrs",
132
- # taxcalc.py
133
- "static_baseline_calc",
134
- "add_weighted_metrics",
135
- "n65",
136
- "calc_df",
137
- "recalculate",
138
- # ubi.py
139
- "ubi_or_bens",
140
- # utils.py
141
- "ordinal_label",
142
- "dedup_list",
143
- "listify",
144
- "flatten",
145
- "cartesian_product",
146
- # weighted.py
147
- "weight",
148
- "weighted_sum",
149
- "weighted_mean",
150
- "weighted_quantile",
151
- "weighted_median",
152
- "add_weighted_quantiles",
153
- "quantile_chg",
154
- # microseries.py
155
- "MicroSeries",
156
- "MicroSeriesGroupBy",
157
- # microdataframe.py
158
- "MicroDataFrame",
159
- "MicroDataFrameGroupBy",
160
- ]
@@ -1,85 +0,0 @@
1
- import distutils.version
2
- import importlib
3
- import types
4
- import warnings
5
- from typing import Optional, Union
6
-
7
- # Adapted from:
8
- # https://github.com/pandas-dev/pandas/blob/master/pandas/compat/_optional.py
9
-
10
- VERSIONS = {
11
- "taxcalc": "2.0.0",
12
- }
13
-
14
-
15
- def _get_version(module: types.ModuleType) -> str:
16
- """
17
-
18
- :param module: types.ModuleType:
19
- :param module: types.ModuleType:
20
-
21
- """
22
- version = getattr(module, "__version__", None)
23
- if version is None:
24
- # xlrd uses a capitalized attribute name
25
- version = getattr(module, "__VERSION__", None)
26
-
27
- if version is None:
28
- raise ImportError(f"Can't determine version for {module.__name__}")
29
- return version
30
-
31
-
32
- def import_optional_dependency(
33
- name: str,
34
- extra: Optional[str] = "",
35
- raise_on_missing: Optional[bool] = True,
36
- on_version: Optional[str] = "raise",
37
- ) -> Union[types.ModuleType, None]:
38
- """Import an optional dependency. By default, if a dependency is missing an
39
- ImportError with a nice message will be raised. If a dependency is present,
40
- but too old, we raise.
41
-
42
- :param name: The module name. This should be top-level only, so that the
43
- version may be checked.
44
- :type name: str
45
- :param extra: Additional text to include in the ImportError message.
46
- :type extra: str
47
- :param raise_on_missing: Whether to raise if the optional dependency is
48
- not found. When False and the module is not present, None is returned.
49
- :type raise_on_missing: bool, default True
50
- :param on_version: What to do when a dependency's version is too old.
51
- * raise : Raise an ImportError
52
- * warn : Warn that the version is too old. Returns None
53
- * ignore: Return the module, even if the version is too old.
54
- It's expected that users validate the version locally when
55
- :type on_version: str {'raise', 'warn'}
56
- """
57
- msg = (
58
- f"Missing optional dependency '{name}'. {extra} "
59
- f"Use pip or conda to install {name}."
60
- )
61
- try:
62
- module = importlib.import_module(name)
63
- except ImportError:
64
- if raise_on_missing:
65
- raise ImportError(msg) from None
66
- else:
67
- return None
68
-
69
- minimum_version = VERSIONS.get(name)
70
- if minimum_version:
71
- version = _get_version(module)
72
- if distutils.version.LooseVersion(version) < minimum_version:
73
- assert on_version in {"warn", "raise", "ignore"}
74
- msg = (
75
- f"microdf requires version '{minimum_version}' or newer of "
76
- f"'{name}' "
77
- f"(version '{version}' currently installed)."
78
- )
79
- if on_version == "warn":
80
- warnings.warn(msg, UserWarning)
81
- return None
82
- elif on_version == "raise":
83
- raise ImportError(msg)
84
-
85
- return module