microunit 0.1.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.
- microunit-0.1.0/.gitignore +11 -0
- microunit-0.1.0/CHANGELOG.md +14 -0
- microunit-0.1.0/LICENSE +21 -0
- microunit-0.1.0/PKG-INFO +183 -0
- microunit-0.1.0/README.md +153 -0
- microunit-0.1.0/pyproject.toml +112 -0
- microunit-0.1.0/src/microunit/__init__.py +61 -0
- microunit-0.1.0/src/microunit/core.py +189 -0
- microunit-0.1.0/src/microunit/data/dependent_gross_income_limit.yaml +88 -0
- microunit-0.1.0/src/microunit/diagnostics.py +82 -0
- microunit-0.1.0/src/microunit/py.typed +1 -0
- microunit-0.1.0/src/microunit/registry.py +51 -0
- microunit-0.1.0/src/microunit/rule_helpers.py +155 -0
- microunit-0.1.0/src/microunit/tax_unit_construction.py +891 -0
- microunit-0.1.0/src/microunit/units/__init__.py +26 -0
- microunit-0.1.0/src/microunit/units/_helpers.py +22 -0
- microunit-0.1.0/src/microunit/units/medicaid.py +44 -0
- microunit-0.1.0/src/microunit/units/passthrough.py +27 -0
- microunit-0.1.0/src/microunit/units/programs.py +56 -0
- microunit-0.1.0/src/microunit/units/snap.py +53 -0
- microunit-0.1.0/src/microunit/units/spm.py +57 -0
- microunit-0.1.0/src/microunit/units/tax.py +88 -0
- microunit-0.1.0/tests/test_core.py +38 -0
- microunit-0.1.0/tests/test_diagnostics.py +42 -0
- microunit-0.1.0/tests/test_import.py +38 -0
- microunit-0.1.0/tests/test_tax_partition_adapter.py +75 -0
- microunit-0.1.0/tests/test_tax_unit_construction.py +441 -0
- microunit-0.1.0/tests/test_units.py +112 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
<!-- towncrier release notes start -->
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-05-30
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Initial release. Rules-based tax-unit construction engine (`construct_tax_units`, `policyengine` and `census_documented` modes) extracted from policyengine-us-data, conservative SPM/SNAP/Medicaid-MAGI unit adapters, partition primitives (`UnitPartition`, `EgoUnitMembership`), and partition-match diagnostics.
|
microunit-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 PolicyEngine
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
microunit-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: microunit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Policy unit assignment for PolicyEngine's microdata stack
|
|
5
|
+
Project-URL: Repository, https://github.com/PolicyEngine/microunit
|
|
6
|
+
Author-email: PolicyEngine <hello@policyengine.org>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: microdata,microplex,policy-simulation,spm,tax-units,unit-assignment
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Requires-Dist: numpy>=1.24
|
|
21
|
+
Requires-Dist: pandas>=2.0
|
|
22
|
+
Requires-Dist: pyyaml>=6.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.1; extra == 'dev'
|
|
28
|
+
Requires-Dist: towncrier>=24.8.0; extra == 'dev'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# microunit
|
|
32
|
+
|
|
33
|
+
`microunit` is PolicyEngine's unit-assignment package for microdata.
|
|
34
|
+
|
|
35
|
+
It is part of the PolicyEngine microdata stack:
|
|
36
|
+
|
|
37
|
+
- `microimpute`: fill missing variables and transfer attributes across data
|
|
38
|
+
sources.
|
|
39
|
+
- `microcalibrate`, eventually maybe `microweight`: align microdata to external
|
|
40
|
+
targets.
|
|
41
|
+
- `microunit`: construct policy units from person and relationship records.
|
|
42
|
+
- `microplex`: synthesize, rebuild, and evaluate full microdata systems.
|
|
43
|
+
|
|
44
|
+
It separates "who belongs with whom" from benefit and tax formulas. The same
|
|
45
|
+
person table can have several policy units layered on top of it:
|
|
46
|
+
|
|
47
|
+
- SPM units for poverty measurement.
|
|
48
|
+
- Tax units for filing and dependency rules.
|
|
49
|
+
- SNAP units for food assistance eligibility.
|
|
50
|
+
- Medicaid MAGI households, which are usually focal-person units rather than a
|
|
51
|
+
single partition of the household.
|
|
52
|
+
|
|
53
|
+
The package starts with the common primitives those systems need:
|
|
54
|
+
|
|
55
|
+
- `UnitPartition`: one unit ID per person, useful for SPM, tax, and many SNAP
|
|
56
|
+
assignment outputs.
|
|
57
|
+
- `EgoUnitMembership`: one membership set per focal person, useful for MAGI-like
|
|
58
|
+
rules where units can overlap.
|
|
59
|
+
- SPM simplification adapters for programs whose true unit rules are not yet
|
|
60
|
+
implemented.
|
|
61
|
+
- Diagnostics for comparing partitions within households.
|
|
62
|
+
- Conservative adapters that preserve existing unit IDs from source data.
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
uv pip install -e ".[dev]"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Example
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import pandas as pd
|
|
74
|
+
from microunit.units import assign_spm_partition
|
|
75
|
+
|
|
76
|
+
persons = pd.DataFrame(
|
|
77
|
+
{
|
|
78
|
+
"person_id": [1, 2, 3],
|
|
79
|
+
"household_id": [10, 10, 10],
|
|
80
|
+
"family_id": [100, 100, 101],
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
partition = assign_spm_partition(persons)
|
|
85
|
+
print(partition.to_frame())
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Rules-based tax-unit construction
|
|
89
|
+
|
|
90
|
+
`microunit` includes the rules-based tax-unit / filing-status construction
|
|
91
|
+
engine extracted from
|
|
92
|
+
[`policyengine-us-data`](https://github.com/PolicyEngine/policyengine-us-data).
|
|
93
|
+
It applies federal filing and dependency rules to assign people into tax
|
|
94
|
+
units, infer each person's role (head / spouse / dependent), and infer a
|
|
95
|
+
filing status per unit. It is the same engine reused across the CPS and ACS
|
|
96
|
+
pipelines there, and is **source-agnostic**: it operates on
|
|
97
|
+
already-normalized, CPS-like person frames. It is consumed by
|
|
98
|
+
`policyengine-us-data` and `microplex-us`.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
import pandas as pd
|
|
102
|
+
from microunit import construct_tax_units
|
|
103
|
+
|
|
104
|
+
# person uses CPS-like column names (see "Input contract" below).
|
|
105
|
+
person_assignments, tax_unit = construct_tax_units(person, year=2024)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`construct_tax_units(person, year, mode="policyengine")` returns:
|
|
109
|
+
|
|
110
|
+
- **`person_assignments`** (indexed like the input): `TAX_ID` (`int64`,
|
|
111
|
+
dense 1-based id), `tax_unit_role_input` (bytes: `HEAD` / `SPOUSE` /
|
|
112
|
+
`DEPENDENT`), `is_related_to_head_or_spouse` (bool).
|
|
113
|
+
- **`tax_unit`** (one row per `TAX_ID`): `filing_status_input` (bytes:
|
|
114
|
+
`JOINT` / `HEAD_OF_HOUSEHOLD` / `SURVIVING_SPOUSE` / `SEPARATE` /
|
|
115
|
+
`SINGLE`).
|
|
116
|
+
|
|
117
|
+
The string columns are byte strings (the HDF5-friendly encoding used by the
|
|
118
|
+
source pipeline); decode with `.decode()`.
|
|
119
|
+
|
|
120
|
+
A `UnitPartition` adapter is also provided:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from microunit.units import construct_tax_partition
|
|
124
|
+
|
|
125
|
+
partition = construct_tax_partition(person, year=2024) # UnitPartition(unit_type="tax")
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Modes
|
|
129
|
+
|
|
130
|
+
- **`"policyengine"`** (default, `microunit.POLICYENGINE_MODE`): PolicyEngine's
|
|
131
|
+
dependency/filing-rule flow.
|
|
132
|
+
- **`"census_documented"`** (`microunit.CENSUS_DOCUMENTED_MODE`): the publicly
|
|
133
|
+
documented Census tax-model flow.
|
|
134
|
+
|
|
135
|
+
### Input contract
|
|
136
|
+
|
|
137
|
+
Required CPS columns (raises `KeyError` if missing): `PH_SEQ`, `A_LINENO`,
|
|
138
|
+
`A_AGE`, `A_MARITL`, `A_SPOUSE`, `PEPAR1`, `PEPAR2`, `A_EXPRRP`.
|
|
139
|
+
|
|
140
|
+
Optional evidence columns (used when present, safely defaulted otherwise):
|
|
141
|
+
income components (`WSAL_VAL`, `SEMP_VAL`, `FRSE_VAL`, `INT_VAL`, `DIV_VAL`,
|
|
142
|
+
`RNT_VAL`, `CAP_VAL`, `UC_VAL`, `OI_VAL`, `ANN_VAL`, `PNSN_VAL`, `SS_VAL`),
|
|
143
|
+
total money income (`PTOTVAL`), enrollment (`A_ENRLW`, `A_FTPT`, `A_HSCOL`),
|
|
144
|
+
and disability flags (`PEDISDRS`, `PEDISEAR`, `PEDISEYE`, `PEDISOUT`,
|
|
145
|
+
`PEDISPHY`, `PEDISREM`). Relationship codes follow the CPS ASEC `A_EXPRRP`
|
|
146
|
+
recode, exposed as `microunit.CPSRelationshipCode`.
|
|
147
|
+
|
|
148
|
+
### ACS column mapping is the consumer's responsibility
|
|
149
|
+
|
|
150
|
+
The ACS PUMS -> CPS column mapping (`acs_to_cps_columns.py` in
|
|
151
|
+
`policyengine-us-data`) is **not** part of `microunit`. That ~500-line module
|
|
152
|
+
is ACS-PUMS-specific (`RELSHIPP`/`RELP` translation, marital-status recoding,
|
|
153
|
+
and heuristic spouse/parent-pointer inference, since ACS provides no universal
|
|
154
|
+
spouse or parent pointers) and belongs with the ACS reader. Consumers reading
|
|
155
|
+
ACS should map their PUMS columns onto the CPS-like contract above and then
|
|
156
|
+
call `construct_tax_units`. Accordingly, the ACS-specific tests from
|
|
157
|
+
`policyengine-us-data` remain there; the full CPS construction test suite is
|
|
158
|
+
ported here.
|
|
159
|
+
|
|
160
|
+
### Packaged data
|
|
161
|
+
|
|
162
|
+
The qualifying-relative gross income limit (the personal/dependent exemption
|
|
163
|
+
amount under IRC 151(d), used by the IRC 152(d)(1)(B) gross income test) ships
|
|
164
|
+
as package data at `microunit/data/dependent_gross_income_limit.yaml` and is
|
|
165
|
+
loaded via `importlib.resources`, so the engine does not depend on
|
|
166
|
+
`policyengine-us` being installed.
|
|
167
|
+
|
|
168
|
+
## Scope
|
|
169
|
+
|
|
170
|
+
This package should construct unit assignments and explain them. It should not
|
|
171
|
+
calculate benefits, taxes, or eligibility amounts. Policy engines remain
|
|
172
|
+
responsible for program formulas.
|
|
173
|
+
|
|
174
|
+
Near-term roadmap:
|
|
175
|
+
|
|
176
|
+
1. Move reusable SPM unit assignment out of `spm-calculator`.
|
|
177
|
+
2. Move reusable tax-unit construction out of `policyengine-us-data` /
|
|
178
|
+
`policyengine-us`. (Done -- see "Rules-based tax-unit construction" above.)
|
|
179
|
+
3. Add CPS and ACS source adapters for Microplex.
|
|
180
|
+
4. Use SPM units as the temporary simplification for SNAP, Medicaid/MAGI, and
|
|
181
|
+
other program units.
|
|
182
|
+
5. Replace those simplifications with real program rules once Microplex has a
|
|
183
|
+
stable end-to-end unit pipeline.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# microunit
|
|
2
|
+
|
|
3
|
+
`microunit` is PolicyEngine's unit-assignment package for microdata.
|
|
4
|
+
|
|
5
|
+
It is part of the PolicyEngine microdata stack:
|
|
6
|
+
|
|
7
|
+
- `microimpute`: fill missing variables and transfer attributes across data
|
|
8
|
+
sources.
|
|
9
|
+
- `microcalibrate`, eventually maybe `microweight`: align microdata to external
|
|
10
|
+
targets.
|
|
11
|
+
- `microunit`: construct policy units from person and relationship records.
|
|
12
|
+
- `microplex`: synthesize, rebuild, and evaluate full microdata systems.
|
|
13
|
+
|
|
14
|
+
It separates "who belongs with whom" from benefit and tax formulas. The same
|
|
15
|
+
person table can have several policy units layered on top of it:
|
|
16
|
+
|
|
17
|
+
- SPM units for poverty measurement.
|
|
18
|
+
- Tax units for filing and dependency rules.
|
|
19
|
+
- SNAP units for food assistance eligibility.
|
|
20
|
+
- Medicaid MAGI households, which are usually focal-person units rather than a
|
|
21
|
+
single partition of the household.
|
|
22
|
+
|
|
23
|
+
The package starts with the common primitives those systems need:
|
|
24
|
+
|
|
25
|
+
- `UnitPartition`: one unit ID per person, useful for SPM, tax, and many SNAP
|
|
26
|
+
assignment outputs.
|
|
27
|
+
- `EgoUnitMembership`: one membership set per focal person, useful for MAGI-like
|
|
28
|
+
rules where units can overlap.
|
|
29
|
+
- SPM simplification adapters for programs whose true unit rules are not yet
|
|
30
|
+
implemented.
|
|
31
|
+
- Diagnostics for comparing partitions within households.
|
|
32
|
+
- Conservative adapters that preserve existing unit IDs from source data.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
uv pip install -e ".[dev]"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Example
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import pandas as pd
|
|
44
|
+
from microunit.units import assign_spm_partition
|
|
45
|
+
|
|
46
|
+
persons = pd.DataFrame(
|
|
47
|
+
{
|
|
48
|
+
"person_id": [1, 2, 3],
|
|
49
|
+
"household_id": [10, 10, 10],
|
|
50
|
+
"family_id": [100, 100, 101],
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
partition = assign_spm_partition(persons)
|
|
55
|
+
print(partition.to_frame())
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Rules-based tax-unit construction
|
|
59
|
+
|
|
60
|
+
`microunit` includes the rules-based tax-unit / filing-status construction
|
|
61
|
+
engine extracted from
|
|
62
|
+
[`policyengine-us-data`](https://github.com/PolicyEngine/policyengine-us-data).
|
|
63
|
+
It applies federal filing and dependency rules to assign people into tax
|
|
64
|
+
units, infer each person's role (head / spouse / dependent), and infer a
|
|
65
|
+
filing status per unit. It is the same engine reused across the CPS and ACS
|
|
66
|
+
pipelines there, and is **source-agnostic**: it operates on
|
|
67
|
+
already-normalized, CPS-like person frames. It is consumed by
|
|
68
|
+
`policyengine-us-data` and `microplex-us`.
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import pandas as pd
|
|
72
|
+
from microunit import construct_tax_units
|
|
73
|
+
|
|
74
|
+
# person uses CPS-like column names (see "Input contract" below).
|
|
75
|
+
person_assignments, tax_unit = construct_tax_units(person, year=2024)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`construct_tax_units(person, year, mode="policyengine")` returns:
|
|
79
|
+
|
|
80
|
+
- **`person_assignments`** (indexed like the input): `TAX_ID` (`int64`,
|
|
81
|
+
dense 1-based id), `tax_unit_role_input` (bytes: `HEAD` / `SPOUSE` /
|
|
82
|
+
`DEPENDENT`), `is_related_to_head_or_spouse` (bool).
|
|
83
|
+
- **`tax_unit`** (one row per `TAX_ID`): `filing_status_input` (bytes:
|
|
84
|
+
`JOINT` / `HEAD_OF_HOUSEHOLD` / `SURVIVING_SPOUSE` / `SEPARATE` /
|
|
85
|
+
`SINGLE`).
|
|
86
|
+
|
|
87
|
+
The string columns are byte strings (the HDF5-friendly encoding used by the
|
|
88
|
+
source pipeline); decode with `.decode()`.
|
|
89
|
+
|
|
90
|
+
A `UnitPartition` adapter is also provided:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from microunit.units import construct_tax_partition
|
|
94
|
+
|
|
95
|
+
partition = construct_tax_partition(person, year=2024) # UnitPartition(unit_type="tax")
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Modes
|
|
99
|
+
|
|
100
|
+
- **`"policyengine"`** (default, `microunit.POLICYENGINE_MODE`): PolicyEngine's
|
|
101
|
+
dependency/filing-rule flow.
|
|
102
|
+
- **`"census_documented"`** (`microunit.CENSUS_DOCUMENTED_MODE`): the publicly
|
|
103
|
+
documented Census tax-model flow.
|
|
104
|
+
|
|
105
|
+
### Input contract
|
|
106
|
+
|
|
107
|
+
Required CPS columns (raises `KeyError` if missing): `PH_SEQ`, `A_LINENO`,
|
|
108
|
+
`A_AGE`, `A_MARITL`, `A_SPOUSE`, `PEPAR1`, `PEPAR2`, `A_EXPRRP`.
|
|
109
|
+
|
|
110
|
+
Optional evidence columns (used when present, safely defaulted otherwise):
|
|
111
|
+
income components (`WSAL_VAL`, `SEMP_VAL`, `FRSE_VAL`, `INT_VAL`, `DIV_VAL`,
|
|
112
|
+
`RNT_VAL`, `CAP_VAL`, `UC_VAL`, `OI_VAL`, `ANN_VAL`, `PNSN_VAL`, `SS_VAL`),
|
|
113
|
+
total money income (`PTOTVAL`), enrollment (`A_ENRLW`, `A_FTPT`, `A_HSCOL`),
|
|
114
|
+
and disability flags (`PEDISDRS`, `PEDISEAR`, `PEDISEYE`, `PEDISOUT`,
|
|
115
|
+
`PEDISPHY`, `PEDISREM`). Relationship codes follow the CPS ASEC `A_EXPRRP`
|
|
116
|
+
recode, exposed as `microunit.CPSRelationshipCode`.
|
|
117
|
+
|
|
118
|
+
### ACS column mapping is the consumer's responsibility
|
|
119
|
+
|
|
120
|
+
The ACS PUMS -> CPS column mapping (`acs_to_cps_columns.py` in
|
|
121
|
+
`policyengine-us-data`) is **not** part of `microunit`. That ~500-line module
|
|
122
|
+
is ACS-PUMS-specific (`RELSHIPP`/`RELP` translation, marital-status recoding,
|
|
123
|
+
and heuristic spouse/parent-pointer inference, since ACS provides no universal
|
|
124
|
+
spouse or parent pointers) and belongs with the ACS reader. Consumers reading
|
|
125
|
+
ACS should map their PUMS columns onto the CPS-like contract above and then
|
|
126
|
+
call `construct_tax_units`. Accordingly, the ACS-specific tests from
|
|
127
|
+
`policyengine-us-data` remain there; the full CPS construction test suite is
|
|
128
|
+
ported here.
|
|
129
|
+
|
|
130
|
+
### Packaged data
|
|
131
|
+
|
|
132
|
+
The qualifying-relative gross income limit (the personal/dependent exemption
|
|
133
|
+
amount under IRC 151(d), used by the IRC 152(d)(1)(B) gross income test) ships
|
|
134
|
+
as package data at `microunit/data/dependent_gross_income_limit.yaml` and is
|
|
135
|
+
loaded via `importlib.resources`, so the engine does not depend on
|
|
136
|
+
`policyengine-us` being installed.
|
|
137
|
+
|
|
138
|
+
## Scope
|
|
139
|
+
|
|
140
|
+
This package should construct unit assignments and explain them. It should not
|
|
141
|
+
calculate benefits, taxes, or eligibility amounts. Policy engines remain
|
|
142
|
+
responsible for program formulas.
|
|
143
|
+
|
|
144
|
+
Near-term roadmap:
|
|
145
|
+
|
|
146
|
+
1. Move reusable SPM unit assignment out of `spm-calculator`.
|
|
147
|
+
2. Move reusable tax-unit construction out of `policyengine-us-data` /
|
|
148
|
+
`policyengine-us`. (Done -- see "Rules-based tax-unit construction" above.)
|
|
149
|
+
3. Add CPS and ACS source adapters for Microplex.
|
|
150
|
+
4. Use SPM units as the temporary simplification for SNAP, Medicaid/MAGI, and
|
|
151
|
+
other program units.
|
|
152
|
+
5. Replace those simplifications with real program rules once Microplex has a
|
|
153
|
+
stable end-to-end unit pipeline.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "microunit"
|
|
7
|
+
# Base version; CI (.github/workflows/versioning.yaml) bumps this from the
|
|
8
|
+
# changelog.d fragments on merge to main, so the first release publishes 0.1.0.
|
|
9
|
+
version = "0.1.0"
|
|
10
|
+
description = "Policy unit assignment for PolicyEngine's microdata stack"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
license = "MIT"
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "PolicyEngine", email = "hello@policyengine.org" }
|
|
15
|
+
]
|
|
16
|
+
keywords = [
|
|
17
|
+
"microdata",
|
|
18
|
+
"unit-assignment",
|
|
19
|
+
"microplex",
|
|
20
|
+
"tax-units",
|
|
21
|
+
"spm",
|
|
22
|
+
"policy-simulation",
|
|
23
|
+
]
|
|
24
|
+
classifiers = [
|
|
25
|
+
"Development Status :: 3 - Alpha",
|
|
26
|
+
"Intended Audience :: Science/Research",
|
|
27
|
+
"License :: OSI Approved :: MIT License",
|
|
28
|
+
"Programming Language :: Python :: 3",
|
|
29
|
+
"Programming Language :: Python :: 3.11",
|
|
30
|
+
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
32
|
+
"Programming Language :: Python :: 3.14",
|
|
33
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
34
|
+
]
|
|
35
|
+
requires-python = ">=3.11"
|
|
36
|
+
dependencies = [
|
|
37
|
+
"numpy>=1.24",
|
|
38
|
+
"pandas>=2.0",
|
|
39
|
+
"pyyaml>=6.0",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.optional-dependencies]
|
|
43
|
+
dev = [
|
|
44
|
+
"pytest>=7.0",
|
|
45
|
+
"pytest-cov>=4.0",
|
|
46
|
+
"ruff>=0.1",
|
|
47
|
+
"build>=1.0",
|
|
48
|
+
"towncrier>=24.8.0",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
[project.urls]
|
|
52
|
+
Repository = "https://github.com/PolicyEngine/microunit"
|
|
53
|
+
|
|
54
|
+
[tool.hatch.build.targets.wheel]
|
|
55
|
+
packages = ["src/microunit"]
|
|
56
|
+
# Ship packaged rule data (the qualifying-relative gross income limit YAML)
|
|
57
|
+
# alongside the Python modules.
|
|
58
|
+
artifacts = ["src/microunit/data/*.yaml"]
|
|
59
|
+
|
|
60
|
+
[tool.hatch.build.targets.sdist]
|
|
61
|
+
include = [
|
|
62
|
+
"src/microunit",
|
|
63
|
+
"tests",
|
|
64
|
+
"README.md",
|
|
65
|
+
"CHANGELOG.md",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[tool.pytest.ini_options]
|
|
69
|
+
testpaths = ["tests"]
|
|
70
|
+
python_files = ["test_*.py"]
|
|
71
|
+
addopts = "-v --tb=short"
|
|
72
|
+
|
|
73
|
+
[tool.ruff]
|
|
74
|
+
line-length = 88
|
|
75
|
+
target-version = "py311"
|
|
76
|
+
|
|
77
|
+
[tool.ruff.lint]
|
|
78
|
+
select = ["E", "F", "I", "N", "W", "UP"]
|
|
79
|
+
ignore = ["E501"]
|
|
80
|
+
|
|
81
|
+
[tool.towncrier]
|
|
82
|
+
package = "microunit"
|
|
83
|
+
directory = "changelog.d"
|
|
84
|
+
filename = "CHANGELOG.md"
|
|
85
|
+
title_format = "## [{version}] - {project_date}"
|
|
86
|
+
issue_format = ""
|
|
87
|
+
underlines = ["", "", ""]
|
|
88
|
+
|
|
89
|
+
[[tool.towncrier.type]]
|
|
90
|
+
directory = "breaking"
|
|
91
|
+
name = "Breaking changes"
|
|
92
|
+
showcontent = true
|
|
93
|
+
|
|
94
|
+
[[tool.towncrier.type]]
|
|
95
|
+
directory = "added"
|
|
96
|
+
name = "Added"
|
|
97
|
+
showcontent = true
|
|
98
|
+
|
|
99
|
+
[[tool.towncrier.type]]
|
|
100
|
+
directory = "changed"
|
|
101
|
+
name = "Changed"
|
|
102
|
+
showcontent = true
|
|
103
|
+
|
|
104
|
+
[[tool.towncrier.type]]
|
|
105
|
+
directory = "fixed"
|
|
106
|
+
name = "Fixed"
|
|
107
|
+
showcontent = true
|
|
108
|
+
|
|
109
|
+
[[tool.towncrier.type]]
|
|
110
|
+
directory = "removed"
|
|
111
|
+
name = "Removed"
|
|
112
|
+
showcontent = true
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Microdata unit assignment primitives."""
|
|
2
|
+
|
|
3
|
+
from microunit.core import EgoUnitMembership, UnitPartition
|
|
4
|
+
from microunit.diagnostics import PartitionMatchReport, partition_match_report
|
|
5
|
+
from microunit.registry import UnitKind, UnitScheme, get_scheme, list_schemes
|
|
6
|
+
from microunit.rule_helpers import (
|
|
7
|
+
REFERENCE_PERSON_CODES,
|
|
8
|
+
REFERENCE_QUALIFYING_CHILD_CODES,
|
|
9
|
+
REFERENCE_QUALIFYING_RELATIVE_CODES,
|
|
10
|
+
REFERENCE_SPOUSE_CODES,
|
|
11
|
+
CPSRelationshipCode,
|
|
12
|
+
dependent_gross_income_limit,
|
|
13
|
+
qualifying_child_age_test,
|
|
14
|
+
reference_relationship_allows_qualifying_child,
|
|
15
|
+
reference_relationship_allows_qualifying_relative,
|
|
16
|
+
related_to_head_or_spouse,
|
|
17
|
+
)
|
|
18
|
+
from microunit.tax_unit_construction import (
|
|
19
|
+
CENSUS_DOCUMENTED_MODE,
|
|
20
|
+
DEPENDENT,
|
|
21
|
+
HEAD,
|
|
22
|
+
POLICYENGINE_MODE,
|
|
23
|
+
SPOUSE,
|
|
24
|
+
SUPPORTED_TAX_UNIT_CONSTRUCTION_MODES,
|
|
25
|
+
construct_tax_units,
|
|
26
|
+
estimate_dependent_gross_income,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
__version__ = "0.1.0"
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"__version__",
|
|
33
|
+
# Core containers
|
|
34
|
+
"EgoUnitMembership",
|
|
35
|
+
"PartitionMatchReport",
|
|
36
|
+
"UnitKind",
|
|
37
|
+
"UnitPartition",
|
|
38
|
+
"UnitScheme",
|
|
39
|
+
"get_scheme",
|
|
40
|
+
"list_schemes",
|
|
41
|
+
"partition_match_report",
|
|
42
|
+
# Rules-based tax-unit construction engine
|
|
43
|
+
"construct_tax_units",
|
|
44
|
+
"estimate_dependent_gross_income",
|
|
45
|
+
"HEAD",
|
|
46
|
+
"SPOUSE",
|
|
47
|
+
"DEPENDENT",
|
|
48
|
+
"POLICYENGINE_MODE",
|
|
49
|
+
"CENSUS_DOCUMENTED_MODE",
|
|
50
|
+
"SUPPORTED_TAX_UNIT_CONSTRUCTION_MODES",
|
|
51
|
+
"CPSRelationshipCode",
|
|
52
|
+
"REFERENCE_PERSON_CODES",
|
|
53
|
+
"REFERENCE_SPOUSE_CODES",
|
|
54
|
+
"REFERENCE_QUALIFYING_CHILD_CODES",
|
|
55
|
+
"REFERENCE_QUALIFYING_RELATIVE_CODES",
|
|
56
|
+
"dependent_gross_income_limit",
|
|
57
|
+
"qualifying_child_age_test",
|
|
58
|
+
"reference_relationship_allows_qualifying_child",
|
|
59
|
+
"reference_relationship_allows_qualifying_relative",
|
|
60
|
+
"related_to_head_or_spouse",
|
|
61
|
+
]
|