policyengine-us 1.365.0__py3-none-any.whl → 1.365.1__py3-none-any.whl
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.
Potentially problematic release.
This version of policyengine-us might be problematic. Click here for more details.
- policyengine_us/tests/utilities/test_ucgid_hierarchical.py +68 -5
- policyengine_us/variables/household/demographic/geographic/ucgid/ucgid.py +68 -71
- policyengine_us/variables/household/demographic/geographic/ucgid/ucgid_str.py +18 -1
- {policyengine_us-1.365.0.dist-info → policyengine_us-1.365.1.dist-info}/METADATA +1 -1
- {policyengine_us-1.365.0.dist-info → policyengine_us-1.365.1.dist-info}/RECORD +8 -8
- {policyengine_us-1.365.0.dist-info → policyengine_us-1.365.1.dist-info}/WHEEL +0 -0
- {policyengine_us-1.365.0.dist-info → policyengine_us-1.365.1.dist-info}/entry_points.txt +0 -0
- {policyengine_us-1.365.0.dist-info → policyengine_us-1.365.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Test script demonstrating UCGID hierarchical functionality.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
+
import numpy as np
|
|
5
6
|
from policyengine_us import Microsimulation
|
|
6
7
|
from policyengine_us.variables.household.demographic.geographic.ucgid.ucgid_enum import (
|
|
7
8
|
UCGID,
|
|
@@ -18,19 +19,16 @@ class TestUCGIDHierarchical:
|
|
|
18
19
|
# Test Congressional District (CA_23)
|
|
19
20
|
ca_23 = UCGID.CA_23
|
|
20
21
|
ca_23_codes = ca_23.get_hierarchical_codes()
|
|
21
|
-
print(f"CA_23 hierarchical codes: {ca_23_codes}")
|
|
22
22
|
assert ca_23_codes == ["5001800US0623", "0400000US06", "0100000US"]
|
|
23
23
|
|
|
24
24
|
# Test State (CA)
|
|
25
25
|
ca = UCGID.CA
|
|
26
26
|
ca_codes = ca.get_hierarchical_codes()
|
|
27
|
-
print(f"CA hierarchical codes: {ca_codes}")
|
|
28
27
|
assert ca_codes == ["0400000US06", "0100000US"]
|
|
29
28
|
|
|
30
29
|
# Test US
|
|
31
30
|
us = UCGID.US
|
|
32
31
|
us_codes = us.get_hierarchical_codes()
|
|
33
|
-
print(f"US hierarchical codes: {us_codes}")
|
|
34
32
|
assert us_codes == ["0100000US"]
|
|
35
33
|
|
|
36
34
|
# Test hierarchy matching
|
|
@@ -50,9 +48,74 @@ class TestUCGIDHierarchical:
|
|
|
50
48
|
# Convert the string back to enum to access hierarchical methods
|
|
51
49
|
ucgid_enum = UCGID[ucgid_string]
|
|
52
50
|
hierarchical_codes = ucgid_enum.get_hierarchical_codes()
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
|
|
52
|
+
# Should have 2 hierarchical codes for state-level UCGIDs: [state, US]
|
|
53
|
+
assert len(hierarchical_codes) == 2
|
|
54
|
+
assert (
|
|
55
|
+
hierarchical_codes[1] == "0100000US"
|
|
56
|
+
) # Second code should always be US
|
|
57
|
+
assert hierarchical_codes[0].startswith(
|
|
58
|
+
"0400000US"
|
|
59
|
+
) # First should be state-level
|
|
55
60
|
|
|
56
61
|
# Test hierarchy matching in simulation context
|
|
57
62
|
is_in_us = ucgid_enum.matches_hierarchy("0100000US")
|
|
58
63
|
assert is_in_us == True
|
|
64
|
+
|
|
65
|
+
def test_ucgid_str_variable(self):
|
|
66
|
+
"""Test the UCGID string variable functionality."""
|
|
67
|
+
simulation = Microsimulation()
|
|
68
|
+
ucgid_str_values = simulation.calculate("ucgid_str", "2024")
|
|
69
|
+
|
|
70
|
+
# The UCGID string variable should return a string representation
|
|
71
|
+
ucgid_str = ucgid_str_values.iloc[0]
|
|
72
|
+
assert type(ucgid_str) == str
|
|
73
|
+
assert (
|
|
74
|
+
ucgid_str.startswith("0100000US")
|
|
75
|
+
| ucgid_str.startswith("0400000US")
|
|
76
|
+
| ucgid_str.startswith("5001800US")
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
# Create a basic simulation to test with specific input values
|
|
80
|
+
from policyengine_us import Simulation
|
|
81
|
+
|
|
82
|
+
simulation = Simulation(
|
|
83
|
+
situation={
|
|
84
|
+
"people": {"person": {}},
|
|
85
|
+
"households": {"household": {"members": ["person"]}},
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Set a specific UCGID value for testing (CA_23)
|
|
90
|
+
simulation.set_input("ucgid", 2024, UCGID.CA_23)
|
|
91
|
+
|
|
92
|
+
# Calculate the ucgid_str value
|
|
93
|
+
ucgid_str_values = simulation.calculate("ucgid_str", 2024)
|
|
94
|
+
ucgid_str = ucgid_str_values[0]
|
|
95
|
+
|
|
96
|
+
# Verify it contains all three hierarchical codes
|
|
97
|
+
assert ucgid_str == "5001800US0623,0400000US06,0100000US"
|
|
98
|
+
|
|
99
|
+
def test_ucgid_microsimulation_input_override(self):
|
|
100
|
+
"""Test setting UCGID input for all households in a microsimulation."""
|
|
101
|
+
microsim = Microsimulation()
|
|
102
|
+
|
|
103
|
+
# Get initial values
|
|
104
|
+
ucgid_before = microsim.calculate("ucgid", 2024)
|
|
105
|
+
num_households = len(ucgid_before)
|
|
106
|
+
|
|
107
|
+
# Set all households to CA_23
|
|
108
|
+
input_array = np.array([UCGID.CA_23] * num_households)
|
|
109
|
+
microsim.set_input("ucgid", 2024, input_array)
|
|
110
|
+
|
|
111
|
+
# Verify the input was set
|
|
112
|
+
ucgid_after = microsim.calculate("ucgid", 2024)
|
|
113
|
+
after_values = ucgid_after.values
|
|
114
|
+
assert all(val == "CA_23" for val in after_values)
|
|
115
|
+
assert len(set(after_values)) == 1
|
|
116
|
+
|
|
117
|
+
# Test that ucgid_str now returns hierarchical codes for all households
|
|
118
|
+
ucgid_str_values = microsim.calculate("ucgid_str", 2024)
|
|
119
|
+
expected_str = "5001800US0623,0400000US06,0100000US"
|
|
120
|
+
str_values = ucgid_str_values.values
|
|
121
|
+
assert all(str_val == expected_str for str_val in str_values)
|
|
@@ -20,78 +20,75 @@ class ucgid(Variable):
|
|
|
20
20
|
def formula(household, period, parameters):
|
|
21
21
|
simulation: Simulation = household.simulation
|
|
22
22
|
|
|
23
|
-
#
|
|
24
|
-
|
|
23
|
+
# Check if this variable has been set as input
|
|
24
|
+
if simulation.get_holder("ucgid").get_known_periods():
|
|
25
|
+
return household("ucgid", period)
|
|
25
26
|
|
|
26
|
-
#
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
# Try to derive from state_code
|
|
28
|
+
state_code_enum = household("state_code", period)
|
|
29
|
+
state_code_strings = state_code_enum.decode_to_str()
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
31
|
+
# Map state codes to UCGID state values
|
|
32
|
+
state_mapping = {
|
|
33
|
+
"AL": UCGID.AL,
|
|
34
|
+
"AK": UCGID.AK,
|
|
35
|
+
"AZ": UCGID.AZ,
|
|
36
|
+
"AR": UCGID.AR,
|
|
37
|
+
"CA": UCGID.CA,
|
|
38
|
+
"CO": UCGID.CO,
|
|
39
|
+
"CT": UCGID.CT,
|
|
40
|
+
"DE": UCGID.DE,
|
|
41
|
+
"DC": UCGID.DC,
|
|
42
|
+
"FL": UCGID.FL,
|
|
43
|
+
"GA": UCGID.GA,
|
|
44
|
+
"HI": UCGID.HI,
|
|
45
|
+
"ID": UCGID.ID,
|
|
46
|
+
"IL": UCGID.IL,
|
|
47
|
+
"IN": UCGID.IN,
|
|
48
|
+
"IA": UCGID.IA,
|
|
49
|
+
"KS": UCGID.KS,
|
|
50
|
+
"KY": UCGID.KY,
|
|
51
|
+
"LA": UCGID.LA,
|
|
52
|
+
"ME": UCGID.ME,
|
|
53
|
+
"MD": UCGID.MD,
|
|
54
|
+
"MA": UCGID.MA,
|
|
55
|
+
"MI": UCGID.MI,
|
|
56
|
+
"MN": UCGID.MN,
|
|
57
|
+
"MS": UCGID.MS,
|
|
58
|
+
"MO": UCGID.MO,
|
|
59
|
+
"MT": UCGID.MT,
|
|
60
|
+
"NE": UCGID.NE,
|
|
61
|
+
"NV": UCGID.NV,
|
|
62
|
+
"NH": UCGID.NH,
|
|
63
|
+
"NJ": UCGID.NJ,
|
|
64
|
+
"NM": UCGID.NM,
|
|
65
|
+
"NY": UCGID.NY,
|
|
66
|
+
"NC": UCGID.NC,
|
|
67
|
+
"ND": UCGID.ND,
|
|
68
|
+
"OH": UCGID.OH,
|
|
69
|
+
"OK": UCGID.OK,
|
|
70
|
+
"OR": UCGID.OR,
|
|
71
|
+
"PA": UCGID.PA,
|
|
72
|
+
"RI": UCGID.RI,
|
|
73
|
+
"SC": UCGID.SC,
|
|
74
|
+
"SD": UCGID.SD,
|
|
75
|
+
"TN": UCGID.TN,
|
|
76
|
+
"TX": UCGID.TX,
|
|
77
|
+
"UT": UCGID.UT,
|
|
78
|
+
"VT": UCGID.VT,
|
|
79
|
+
"VA": UCGID.VA,
|
|
80
|
+
"WA": UCGID.WA,
|
|
81
|
+
"WV": UCGID.WV,
|
|
82
|
+
"WI": UCGID.WI,
|
|
83
|
+
"WY": UCGID.WY,
|
|
84
|
+
}
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
result[i] = UCGID.US
|
|
86
|
+
# Convert state code strings to UCGID values
|
|
87
|
+
result = np.empty(len(state_code_strings), dtype=object)
|
|
88
|
+
for i, state_str in enumerate(state_code_strings):
|
|
89
|
+
if state_str in state_mapping:
|
|
90
|
+
result[i] = state_mapping[state_str]
|
|
91
|
+
else:
|
|
92
|
+
result[i] = UCGID.US
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
# Default fallback
|
|
97
|
-
return np.full(household.count, UCGID.US, dtype=object)
|
|
94
|
+
return result
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
from policyengine_us.model_api import *
|
|
2
|
+
from policyengine_us.variables.household.demographic.geographic.ucgid.ucgid_enum import (
|
|
3
|
+
UCGID,
|
|
4
|
+
)
|
|
2
5
|
|
|
3
6
|
|
|
4
7
|
class ucgid_str(Variable):
|
|
@@ -9,4 +12,18 @@ class ucgid_str(Variable):
|
|
|
9
12
|
definition_period = YEAR
|
|
10
13
|
|
|
11
14
|
def formula(household, period, parameters):
|
|
12
|
-
|
|
15
|
+
import numpy as np
|
|
16
|
+
|
|
17
|
+
ucgid_enum_names = household("ucgid", period).decode_to_str()
|
|
18
|
+
|
|
19
|
+
# Convert each enum name to its hierarchical codes
|
|
20
|
+
result = []
|
|
21
|
+
for enum_name in ucgid_enum_names:
|
|
22
|
+
# Get the enum instance from its name
|
|
23
|
+
ucgid_enum = UCGID[enum_name]
|
|
24
|
+
|
|
25
|
+
# Get all hierarchical codes and join with commas
|
|
26
|
+
hierarchical_codes = ucgid_enum.get_hierarchical_codes()
|
|
27
|
+
result.append(",".join(hierarchical_codes))
|
|
28
|
+
|
|
29
|
+
return np.array(result)
|
|
@@ -5136,7 +5136,7 @@ policyengine_us/tests/policy/contrib/ubi_center/flat_tax.yaml,sha256=O6krfJ2rovW
|
|
|
5136
5136
|
policyengine_us/tests/policy/reform/ctc_expansion.yaml,sha256=soq-LqWwbb7fNQJFphx_1gSc8uDGOhtr-5P93oY2Mpg,1596
|
|
5137
5137
|
policyengine_us/tests/policy/reform/winship.yaml,sha256=OPfsoZ0NrlPU25hJadZXycrYLaM0wPUGXjBrn6_8gR4,1706
|
|
5138
5138
|
policyengine_us/tests/utilities/test_load_county_fips_dataset.py,sha256=QAURDL6IMN5gafUOcTri1PUet6khLNZ_Bov6NdW_pMM,4397
|
|
5139
|
-
policyengine_us/tests/utilities/test_ucgid_hierarchical.py,sha256=
|
|
5139
|
+
policyengine_us/tests/utilities/test_ucgid_hierarchical.py,sha256=WZYqWHw6-QQAv0Wd3bGgAcgPgZ0ILhOxpC-kgo4HRkU,4532
|
|
5140
5140
|
policyengine_us/tests/variables/gov/states/vt/tax/income/vt_eitc.yaml,sha256=gE-ZtclGqoFKs87k9VUgKEoVO2iZkFBq4k-ixGtde14,2341
|
|
5141
5141
|
policyengine_us/tests/variables/gov/states/vt/tax/income/adjusted_gross_income/subtractions/retirement_income_exemption/vt_military_retirement_income_based_exemption.yaml,sha256=b5I5ekAoDCrojCLwEZMoBEDdUX9zDw1bM-4iQLmyTng,3267
|
|
5142
5142
|
policyengine_us/tests/variables/gov/states/vt/tax/income/credits/vt_veteran_tax_credit.yaml,sha256=51NtThz2bNwVD7o-2VXZqplDjKUAYzIiIzyL1PfXK94,3244
|
|
@@ -7785,9 +7785,9 @@ policyengine_us/variables/household/demographic/geographic/county/county_str.py,
|
|
|
7785
7785
|
policyengine_us/variables/household/demographic/geographic/county/first_county_in_state.py,sha256=yXCj-LVjxPeILIg42ijefTmi_j4NxJwX0kMtoE47xic,1578
|
|
7786
7786
|
policyengine_us/variables/household/demographic/geographic/state/average_home_energy_use_in_state.py,sha256=aaGYAXLU7tsx-A9NW4nyLij5J5mp0WTRXsyObngekvY,319
|
|
7787
7787
|
policyengine_us/variables/household/demographic/geographic/state/in_state.py,sha256=o3ksZCOHtlJ1JGHIXAPlqcs5-rVbTgOCcDdN1-fYqmA,551
|
|
7788
|
-
policyengine_us/variables/household/demographic/geographic/ucgid/ucgid.py,sha256=
|
|
7788
|
+
policyengine_us/variables/household/demographic/geographic/ucgid/ucgid.py,sha256=SwONHVRvHmUFHvPZQMYY7Y9e7gz74kisLjJICpHdyKg,2874
|
|
7789
7789
|
policyengine_us/variables/household/demographic/geographic/ucgid/ucgid_enum.py,sha256=dkeusTBI1j4xAGmRFkfSsyT3Hq5gHZwRUkSeISeNbx0,15636
|
|
7790
|
-
policyengine_us/variables/household/demographic/geographic/ucgid/ucgid_str.py,sha256=
|
|
7790
|
+
policyengine_us/variables/household/demographic/geographic/ucgid/ucgid_str.py,sha256=GnIRg2tc0376YazPX7wm7YQgMQaYPm2Au47vc1E5JcM,914
|
|
7791
7791
|
policyengine_us/variables/household/demographic/geographic/zip_code/three_digit_zip_code.py,sha256=7q0FQRahTOINiK2vlAyHEa5xIKowM5Kgl60-kR3ZuWU,426
|
|
7792
7792
|
policyengine_us/variables/household/demographic/geographic/zip_code/zip_code.py,sha256=PZiLb84BgKQ_Suvd6iUiEnzySu3Vtiv8FOlfB4rnagQ,1691
|
|
7793
7793
|
policyengine_us/variables/household/demographic/household/bedrooms.py,sha256=4ltdIRLdmeuTKAskn4pdgxZuxEE-4rz0ffPnIKobc-o,164
|
|
@@ -8236,8 +8236,8 @@ policyengine_us/variables/input/farm_income.py,sha256=BEKxYmHNNnWJAAvULl5qZJigy5
|
|
|
8236
8236
|
policyengine_us/variables/input/geography.py,sha256=XmBlgXhzBoLRKk6R8taVZHqUw1eU8MbNeGS9iJ7_l44,4506
|
|
8237
8237
|
policyengine_us/variables/input/self_employment_income.py,sha256=PwsGz8R4lRikKWUYOhsC0qosNNLXq4f5SQmfw4S3mk8,511
|
|
8238
8238
|
policyengine_us/variables/input/self_employment_income_before_lsr.py,sha256=E8fcX9Nlyqz8dziHhQv_euutdmoIwFMMWePUwbbwv_w,379
|
|
8239
|
-
policyengine_us-1.365.
|
|
8240
|
-
policyengine_us-1.365.
|
|
8241
|
-
policyengine_us-1.365.
|
|
8242
|
-
policyengine_us-1.365.
|
|
8243
|
-
policyengine_us-1.365.
|
|
8239
|
+
policyengine_us-1.365.1.dist-info/METADATA,sha256=HOpqZAHTPNFrdBmVMwFA27fcbSixBqddzUTZwqQ9qk8,1693
|
|
8240
|
+
policyengine_us-1.365.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8241
|
+
policyengine_us-1.365.1.dist-info/entry_points.txt,sha256=MLaqNyNTbReALyKNkde85VkuFFpdPWAcy8VRG1mjczc,57
|
|
8242
|
+
policyengine_us-1.365.1.dist-info/licenses/LICENSE,sha256=2N5ReRelkdqkR9a-KP-y-shmcD5P62XoYiG-miLTAzo,34519
|
|
8243
|
+
policyengine_us-1.365.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|