policyengine-us 1.382.0__py3-none-any.whl → 1.383.0__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.

@@ -142,3 +142,27 @@ class state_fips(Variable):
142
142
  definition_period = YEAR
143
143
  documentation = "State FIPS code"
144
144
  default_value = 6
145
+
146
+
147
+ class congressional_district_geoid(Variable):
148
+ value_type = int
149
+ label = "Congressional district GEOID"
150
+ entity = Household
151
+ definition_period = YEAR
152
+ documentation = """Congressional district geographic identifier stored as an integer.
153
+
154
+ Format: SSDD where SS is the 2-digit state FIPS code and DD is the 2-digit district number.
155
+
156
+ Examples:
157
+ - Alabama (FIPS 01) district 01 is stored as 101
158
+ - Alabama (FIPS 01) district 07 is stored as 107
159
+ - North Carolina (FIPS 37) district 01 is stored as 3701
160
+ - California (FIPS 06) district 52 is stored as 652
161
+
162
+ To extract components:
163
+ - State FIPS: geoid // 100
164
+ - District number: geoid % 100
165
+
166
+ Note: Leading zeros are not preserved in the integer storage (e.g., 0101 becomes 101),
167
+ but the value remains unique and unambiguous since the format is always interpreted as SSDD."""
168
+ default_value = 0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: policyengine-us
3
- Version: 1.382.0
3
+ Version: 1.383.0
4
4
  Summary: Add your description here.
5
5
  Author-email: PolicyEngine <hello@policyengine.org>
6
6
  License-File: LICENSE
@@ -5186,7 +5186,6 @@ policyengine_us/tests/policy/contrib/ubi_center/flat_tax.yaml,sha256=O6krfJ2rovW
5186
5186
  policyengine_us/tests/policy/reform/ctc_expansion.yaml,sha256=soq-LqWwbb7fNQJFphx_1gSc8uDGOhtr-5P93oY2Mpg,1596
5187
5187
  policyengine_us/tests/policy/reform/winship.yaml,sha256=OPfsoZ0NrlPU25hJadZXycrYLaM0wPUGXjBrn6_8gR4,1706
5188
5188
  policyengine_us/tests/utilities/test_load_county_fips_dataset.py,sha256=QAURDL6IMN5gafUOcTri1PUet6khLNZ_Bov6NdW_pMM,4397
5189
- policyengine_us/tests/utilities/test_ucgid_hierarchical.py,sha256=WZYqWHw6-QQAv0Wd3bGgAcgPgZ0ILhOxpC-kgo4HRkU,4532
5190
5189
  policyengine_us/tests/variables/gov/states/vt/tax/income/vt_eitc.yaml,sha256=gE-ZtclGqoFKs87k9VUgKEoVO2iZkFBq4k-ixGtde14,2341
5191
5190
  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
5192
5191
  policyengine_us/tests/variables/gov/states/vt/tax/income/credits/vt_veteran_tax_credit.yaml,sha256=51NtThz2bNwVD7o-2VXZqplDjKUAYzIiIzyL1PfXK94,3244
@@ -7855,9 +7854,6 @@ policyengine_us/variables/household/demographic/geographic/county/county_str.py,
7855
7854
  policyengine_us/variables/household/demographic/geographic/county/first_county_in_state.py,sha256=yXCj-LVjxPeILIg42ijefTmi_j4NxJwX0kMtoE47xic,1578
7856
7855
  policyengine_us/variables/household/demographic/geographic/state/average_home_energy_use_in_state.py,sha256=aaGYAXLU7tsx-A9NW4nyLij5J5mp0WTRXsyObngekvY,319
7857
7856
  policyengine_us/variables/household/demographic/geographic/state/in_state.py,sha256=o3ksZCOHtlJ1JGHIXAPlqcs5-rVbTgOCcDdN1-fYqmA,551
7858
- policyengine_us/variables/household/demographic/geographic/ucgid/ucgid.py,sha256=SwONHVRvHmUFHvPZQMYY7Y9e7gz74kisLjJICpHdyKg,2874
7859
- policyengine_us/variables/household/demographic/geographic/ucgid/ucgid_enum.py,sha256=dkeusTBI1j4xAGmRFkfSsyT3Hq5gHZwRUkSeISeNbx0,15636
7860
- policyengine_us/variables/household/demographic/geographic/ucgid/ucgid_str.py,sha256=GnIRg2tc0376YazPX7wm7YQgMQaYPm2Au47vc1E5JcM,914
7861
7857
  policyengine_us/variables/household/demographic/geographic/zip_code/three_digit_zip_code.py,sha256=7q0FQRahTOINiK2vlAyHEa5xIKowM5Kgl60-kR3ZuWU,426
7862
7858
  policyengine_us/variables/household/demographic/geographic/zip_code/zip_code.py,sha256=3J8RfnIIsmw4_5gF5yZHmATt2cNskyKQR0lncCvOQx0,1691
7863
7859
  policyengine_us/variables/household/demographic/household/bedrooms.py,sha256=4ltdIRLdmeuTKAskn4pdgxZuxEE-4rz0ffPnIKobc-o,164
@@ -8305,11 +8301,11 @@ policyengine_us/variables/household/income/tax_unit/us_govt_interest.py,sha256=L
8305
8301
  policyengine_us/variables/input/employment_income.py,sha256=f85M5Jy8kHmkDId0j9lCE30R6htNQ-Hg74ko9cLupmI,505
8306
8302
  policyengine_us/variables/input/employment_income_before_lsr.py,sha256=X4PBfylDs40hw6jwHPL_B0JcBkqrKCFU-beQEDFoJTE,364
8307
8303
  policyengine_us/variables/input/farm_income.py,sha256=BEKxYmHNNnWJAAvULl5qZJigy58ap_bmQB6iHdXLGuo,427
8308
- policyengine_us/variables/input/geography.py,sha256=XmBlgXhzBoLRKk6R8taVZHqUw1eU8MbNeGS9iJ7_l44,4506
8304
+ policyengine_us/variables/input/geography.py,sha256=Ux0ueAf0rhZaflyEqz81UuXP3xKCKBDvoO3CrKhiQEc,5421
8309
8305
  policyengine_us/variables/input/self_employment_income.py,sha256=PwsGz8R4lRikKWUYOhsC0qosNNLXq4f5SQmfw4S3mk8,511
8310
8306
  policyengine_us/variables/input/self_employment_income_before_lsr.py,sha256=E8fcX9Nlyqz8dziHhQv_euutdmoIwFMMWePUwbbwv_w,379
8311
- policyengine_us-1.382.0.dist-info/METADATA,sha256=IedOZfq3uB5TQtWUlKEOkcpevDZbxVKhO0x_B_CLJvk,1649
8312
- policyengine_us-1.382.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8313
- policyengine_us-1.382.0.dist-info/entry_points.txt,sha256=MLaqNyNTbReALyKNkde85VkuFFpdPWAcy8VRG1mjczc,57
8314
- policyengine_us-1.382.0.dist-info/licenses/LICENSE,sha256=2N5ReRelkdqkR9a-KP-y-shmcD5P62XoYiG-miLTAzo,34519
8315
- policyengine_us-1.382.0.dist-info/RECORD,,
8307
+ policyengine_us-1.383.0.dist-info/METADATA,sha256=OHHi_sCwaJcw2LBrsw8bG5acWDrtPQB6Yn6DKyxNSec,1649
8308
+ policyengine_us-1.383.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8309
+ policyengine_us-1.383.0.dist-info/entry_points.txt,sha256=MLaqNyNTbReALyKNkde85VkuFFpdPWAcy8VRG1mjczc,57
8310
+ policyengine_us-1.383.0.dist-info/licenses/LICENSE,sha256=2N5ReRelkdqkR9a-KP-y-shmcD5P62XoYiG-miLTAzo,34519
8311
+ policyengine_us-1.383.0.dist-info/RECORD,,
@@ -1,121 +0,0 @@
1
- """
2
- Test script demonstrating UCGID hierarchical functionality.
3
- """
4
-
5
- import numpy as np
6
- from policyengine_us import Microsimulation
7
- from policyengine_us.variables.household.demographic.geographic.ucgid.ucgid_enum import (
8
- UCGID,
9
- )
10
-
11
-
12
- class TestUCGIDHierarchical:
13
- """Test class for UCGID hierarchical functionality."""
14
-
15
- def test_ucgid_enum_hierarchical_methods(self):
16
- """Test the hierarchical methods on UCGID enum values directly."""
17
- print("\n=== Testing UCGID Enum Hierarchical Methods ===")
18
-
19
- # Test Congressional District (CA_23)
20
- ca_23 = UCGID.CA_23
21
- ca_23_codes = ca_23.get_hierarchical_codes()
22
- assert ca_23_codes == ["5001800US0623", "0400000US06", "0100000US"]
23
-
24
- # Test State (CA)
25
- ca = UCGID.CA
26
- ca_codes = ca.get_hierarchical_codes()
27
- assert ca_codes == ["0400000US06", "0100000US"]
28
-
29
- # Test US
30
- us = UCGID.US
31
- us_codes = us.get_hierarchical_codes()
32
- assert us_codes == ["0100000US"]
33
-
34
- # Test hierarchy matching
35
- assert ca_23.matches_hierarchy("0400000US06") == True
36
- assert ca_23.matches_hierarchy("0100000US") == True
37
- assert ca.matches_hierarchy("5001800US0623") == False
38
-
39
- def test_ucgid_simulation_usage(self):
40
- """Test how UCGID is used in a PolicyEngine simulation."""
41
- simulation = Microsimulation()
42
- ucgid_values = simulation.calculate("ucgid", "2024")
43
-
44
- # The UCGID value should be a string (enum name)
45
- ucgid_string = ucgid_values.iloc[0] # First household
46
- assert type(ucgid_string) == str
47
-
48
- # Convert the string back to enum to access hierarchical methods
49
- ucgid_enum = UCGID[ucgid_string]
50
- hierarchical_codes = ucgid_enum.get_hierarchical_codes()
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
60
-
61
- # Test hierarchy matching in simulation context
62
- is_in_us = ucgid_enum.matches_hierarchy("0100000US")
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)
@@ -1,94 +0,0 @@
1
- from policyengine_us.model_api import *
2
- from policyengine_core.simulations import Simulation
3
- from policyengine_us.variables.household.demographic.geographic.ucgid.ucgid_enum import (
4
- UCGID,
5
- )
6
- import numpy as np
7
-
8
-
9
- class ucgid(Variable):
10
- value_type = Enum
11
- possible_values = UCGID
12
- default_value = UCGID.US
13
- entity = Household
14
- label = "Unified Congressional Geographic Identifier (UCGID)"
15
- definition_period = YEAR
16
- documentation = """
17
- Unified Congressional Geographic Identifier (UCGID) for the household as defined by the U.S. Census Bureau.
18
- """
19
-
20
- def formula(household, period, parameters):
21
- simulation: Simulation = household.simulation
22
-
23
- # Check if this variable has been set as input
24
- if simulation.get_holder("ucgid").get_known_periods():
25
- return household("ucgid", period)
26
-
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()
30
-
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
- }
85
-
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
-
94
- return result
@@ -1,551 +0,0 @@
1
- from policyengine_us.model_api import *
2
- from typing import List
3
-
4
-
5
- class UCGID(Enum):
6
- US = "0100000US"
7
- AL = "0400000US01"
8
- AK = "0400000US02"
9
- AZ = "0400000US04"
10
- AR = "0400000US05"
11
- CA = "0400000US06"
12
- CO = "0400000US08"
13
- CT = "0400000US09"
14
- DE = "0400000US10"
15
- DC = "0400000US11"
16
- FL = "0400000US12"
17
- GA = "0400000US13"
18
- HI = "0400000US15"
19
- ID = "0400000US16"
20
- IL = "0400000US17"
21
- IN = "0400000US18"
22
- IA = "0400000US19"
23
- KS = "0400000US20"
24
- KY = "0400000US21"
25
- LA = "0400000US22"
26
- ME = "0400000US23"
27
- MD = "0400000US24"
28
- MA = "0400000US25"
29
- MI = "0400000US26"
30
- MN = "0400000US27"
31
- MS = "0400000US28"
32
- MO = "0400000US29"
33
- MT = "0400000US30"
34
- NE = "0400000US31"
35
- NV = "0400000US32"
36
- NH = "0400000US33"
37
- NJ = "0400000US34"
38
- NM = "0400000US35"
39
- NY = "0400000US36"
40
- NC = "0400000US37"
41
- ND = "0400000US38"
42
- OH = "0400000US39"
43
- OK = "0400000US40"
44
- OR = "0400000US41"
45
- PA = "0400000US42"
46
- RI = "0400000US44"
47
- SC = "0400000US45"
48
- SD = "0400000US46"
49
- TN = "0400000US47"
50
- TX = "0400000US48"
51
- UT = "0400000US49"
52
- VT = "0400000US50"
53
- VA = "0400000US51"
54
- WA = "0400000US53"
55
- WV = "0400000US54"
56
- WI = "0400000US55"
57
- WY = "0400000US56"
58
- AL_01 = "5001800US0101"
59
- AL_02 = "5001800US0102"
60
- AL_03 = "5001800US0103"
61
- AL_04 = "5001800US0104"
62
- AL_05 = "5001800US0105"
63
- AL_06 = "5001800US0106"
64
- AL_07 = "5001800US0107"
65
- AK_01 = "5001800US0200"
66
- AZ_01 = "5001800US0401"
67
- AZ_02 = "5001800US0402"
68
- AZ_03 = "5001800US0403"
69
- AZ_04 = "5001800US0404"
70
- AZ_05 = "5001800US0405"
71
- AZ_06 = "5001800US0406"
72
- AZ_07 = "5001800US0407"
73
- AZ_08 = "5001800US0408"
74
- AZ_09 = "5001800US0409"
75
- AR_01 = "5001800US0501"
76
- AR_02 = "5001800US0502"
77
- AR_03 = "5001800US0503"
78
- AR_04 = "5001800US0504"
79
- CA_01 = "5001800US0601"
80
- CA_02 = "5001800US0602"
81
- CA_03 = "5001800US0603"
82
- CA_04 = "5001800US0604"
83
- CA_05 = "5001800US0605"
84
- CA_06 = "5001800US0606"
85
- CA_07 = "5001800US0607"
86
- CA_08 = "5001800US0608"
87
- CA_09 = "5001800US0609"
88
- CA_10 = "5001800US0610"
89
- CA_11 = "5001800US0611"
90
- CA_12 = "5001800US0612"
91
- CA_13 = "5001800US0613"
92
- CA_14 = "5001800US0614"
93
- CA_15 = "5001800US0615"
94
- CA_16 = "5001800US0616"
95
- CA_17 = "5001800US0617"
96
- CA_18 = "5001800US0618"
97
- CA_19 = "5001800US0619"
98
- CA_20 = "5001800US0620"
99
- CA_21 = "5001800US0621"
100
- CA_22 = "5001800US0622"
101
- CA_23 = "5001800US0623"
102
- CA_24 = "5001800US0624"
103
- CA_25 = "5001800US0625"
104
- CA_26 = "5001800US0626"
105
- CA_27 = "5001800US0627"
106
- CA_28 = "5001800US0628"
107
- CA_29 = "5001800US0629"
108
- CA_30 = "5001800US0630"
109
- CA_31 = "5001800US0631"
110
- CA_32 = "5001800US0632"
111
- CA_33 = "5001800US0633"
112
- CA_34 = "5001800US0634"
113
- CA_35 = "5001800US0635"
114
- CA_36 = "5001800US0636"
115
- CA_37 = "5001800US0637"
116
- CA_38 = "5001800US0638"
117
- CA_39 = "5001800US0639"
118
- CA_40 = "5001800US0640"
119
- CA_41 = "5001800US0641"
120
- CA_42 = "5001800US0642"
121
- CA_43 = "5001800US0643"
122
- CA_44 = "5001800US0644"
123
- CA_45 = "5001800US0645"
124
- CA_46 = "5001800US0646"
125
- CA_47 = "5001800US0647"
126
- CA_48 = "5001800US0648"
127
- CA_49 = "5001800US0649"
128
- CA_50 = "5001800US0650"
129
- CA_51 = "5001800US0651"
130
- CA_52 = "5001800US0652"
131
- CO_01 = "5001800US0801"
132
- CO_02 = "5001800US0802"
133
- CO_03 = "5001800US0803"
134
- CO_04 = "5001800US0804"
135
- CO_05 = "5001800US0805"
136
- CO_06 = "5001800US0806"
137
- CO_07 = "5001800US0807"
138
- CO_08 = "5001800US0808"
139
- CT_01 = "5001800US0901"
140
- CT_02 = "5001800US0902"
141
- CT_03 = "5001800US0903"
142
- CT_04 = "5001800US0904"
143
- CT_05 = "5001800US0905"
144
- DE_01 = "5001800US1000"
145
- DC_01 = "5001800US1198"
146
- FL_01 = "5001800US1201"
147
- FL_02 = "5001800US1202"
148
- FL_03 = "5001800US1203"
149
- FL_04 = "5001800US1204"
150
- FL_05 = "5001800US1205"
151
- FL_06 = "5001800US1206"
152
- FL_07 = "5001800US1207"
153
- FL_08 = "5001800US1208"
154
- FL_09 = "5001800US1209"
155
- FL_10 = "5001800US1210"
156
- FL_11 = "5001800US1211"
157
- FL_12 = "5001800US1212"
158
- FL_13 = "5001800US1213"
159
- FL_14 = "5001800US1214"
160
- FL_15 = "5001800US1215"
161
- FL_16 = "5001800US1216"
162
- FL_17 = "5001800US1217"
163
- FL_18 = "5001800US1218"
164
- FL_19 = "5001800US1219"
165
- FL_20 = "5001800US1220"
166
- FL_21 = "5001800US1221"
167
- FL_22 = "5001800US1222"
168
- FL_23 = "5001800US1223"
169
- FL_24 = "5001800US1224"
170
- FL_25 = "5001800US1225"
171
- FL_26 = "5001800US1226"
172
- FL_27 = "5001800US1227"
173
- FL_28 = "5001800US1228"
174
- GA_01 = "5001800US1301"
175
- GA_02 = "5001800US1302"
176
- GA_03 = "5001800US1303"
177
- GA_04 = "5001800US1304"
178
- GA_05 = "5001800US1305"
179
- GA_06 = "5001800US1306"
180
- GA_07 = "5001800US1307"
181
- GA_08 = "5001800US1308"
182
- GA_09 = "5001800US1309"
183
- GA_10 = "5001800US1310"
184
- GA_11 = "5001800US1311"
185
- GA_12 = "5001800US1312"
186
- GA_13 = "5001800US1313"
187
- GA_14 = "5001800US1314"
188
- HI_01 = "5001800US1501"
189
- HI_02 = "5001800US1502"
190
- ID_01 = "5001800US1601"
191
- ID_02 = "5001800US1602"
192
- IL_01 = "5001800US1701"
193
- IL_02 = "5001800US1702"
194
- IL_03 = "5001800US1703"
195
- IL_04 = "5001800US1704"
196
- IL_05 = "5001800US1705"
197
- IL_06 = "5001800US1706"
198
- IL_07 = "5001800US1707"
199
- IL_08 = "5001800US1708"
200
- IL_09 = "5001800US1709"
201
- IL_10 = "5001800US1710"
202
- IL_11 = "5001800US1711"
203
- IL_12 = "5001800US1712"
204
- IL_13 = "5001800US1713"
205
- IL_14 = "5001800US1714"
206
- IL_15 = "5001800US1715"
207
- IL_16 = "5001800US1716"
208
- IL_17 = "5001800US1717"
209
- IN_01 = "5001800US1801"
210
- IN_02 = "5001800US1802"
211
- IN_03 = "5001800US1803"
212
- IN_04 = "5001800US1804"
213
- IN_05 = "5001800US1805"
214
- IN_06 = "5001800US1806"
215
- IN_07 = "5001800US1807"
216
- IN_08 = "5001800US1808"
217
- IN_09 = "5001800US1809"
218
- IA_01 = "5001800US1901"
219
- IA_02 = "5001800US1902"
220
- IA_03 = "5001800US1903"
221
- IA_04 = "5001800US1904"
222
- KS_01 = "5001800US2001"
223
- KS_02 = "5001800US2002"
224
- KS_03 = "5001800US2003"
225
- KS_04 = "5001800US2004"
226
- KY_01 = "5001800US2101"
227
- KY_02 = "5001800US2102"
228
- KY_03 = "5001800US2103"
229
- KY_04 = "5001800US2104"
230
- KY_05 = "5001800US2105"
231
- KY_06 = "5001800US2106"
232
- LA_01 = "5001800US2201"
233
- LA_02 = "5001800US2202"
234
- LA_03 = "5001800US2203"
235
- LA_04 = "5001800US2204"
236
- LA_05 = "5001800US2205"
237
- LA_06 = "5001800US2206"
238
- ME_01 = "5001800US2301"
239
- ME_02 = "5001800US2302"
240
- MD_01 = "5001800US2401"
241
- MD_02 = "5001800US2402"
242
- MD_03 = "5001800US2403"
243
- MD_04 = "5001800US2404"
244
- MD_05 = "5001800US2405"
245
- MD_06 = "5001800US2406"
246
- MD_07 = "5001800US2407"
247
- MD_08 = "5001800US2408"
248
- MA_01 = "5001800US2501"
249
- MA_02 = "5001800US2502"
250
- MA_03 = "5001800US2503"
251
- MA_04 = "5001800US2504"
252
- MA_05 = "5001800US2505"
253
- MA_06 = "5001800US2506"
254
- MA_07 = "5001800US2507"
255
- MA_08 = "5001800US2508"
256
- MA_09 = "5001800US2509"
257
- MI_01 = "5001800US2601"
258
- MI_02 = "5001800US2602"
259
- MI_03 = "5001800US2603"
260
- MI_04 = "5001800US2604"
261
- MI_05 = "5001800US2605"
262
- MI_06 = "5001800US2606"
263
- MI_07 = "5001800US2607"
264
- MI_08 = "5001800US2608"
265
- MI_09 = "5001800US2609"
266
- MI_10 = "5001800US2610"
267
- MI_11 = "5001800US2611"
268
- MI_12 = "5001800US2612"
269
- MI_13 = "5001800US2613"
270
- MN_01 = "5001800US2701"
271
- MN_02 = "5001800US2702"
272
- MN_03 = "5001800US2703"
273
- MN_04 = "5001800US2704"
274
- MN_05 = "5001800US2705"
275
- MN_06 = "5001800US2706"
276
- MN_07 = "5001800US2707"
277
- MN_08 = "5001800US2708"
278
- MS_01 = "5001800US2801"
279
- MS_02 = "5001800US2802"
280
- MS_03 = "5001800US2803"
281
- MS_04 = "5001800US2804"
282
- MO_01 = "5001800US2901"
283
- MO_02 = "5001800US2902"
284
- MO_03 = "5001800US2903"
285
- MO_04 = "5001800US2904"
286
- MO_05 = "5001800US2905"
287
- MO_06 = "5001800US2906"
288
- MO_07 = "5001800US2907"
289
- MO_08 = "5001800US2908"
290
- MT_01 = "5001800US3001"
291
- MT_02 = "5001800US3002"
292
- NE_01 = "5001800US3101"
293
- NE_02 = "5001800US3102"
294
- NE_03 = "5001800US3103"
295
- NV_01 = "5001800US3201"
296
- NV_02 = "5001800US3202"
297
- NV_03 = "5001800US3203"
298
- NV_04 = "5001800US3204"
299
- NH_01 = "5001800US3301"
300
- NH_02 = "5001800US3302"
301
- NJ_01 = "5001800US3401"
302
- NJ_02 = "5001800US3402"
303
- NJ_03 = "5001800US3403"
304
- NJ_04 = "5001800US3404"
305
- NJ_05 = "5001800US3405"
306
- NJ_06 = "5001800US3406"
307
- NJ_07 = "5001800US3407"
308
- NJ_08 = "5001800US3408"
309
- NJ_09 = "5001800US3409"
310
- NJ_10 = "5001800US3410"
311
- NJ_11 = "5001800US3411"
312
- NJ_12 = "5001800US3412"
313
- NM_01 = "5001800US3501"
314
- NM_02 = "5001800US3502"
315
- NM_03 = "5001800US3503"
316
- NY_01 = "5001800US3601"
317
- NY_02 = "5001800US3602"
318
- NY_03 = "5001800US3603"
319
- NY_04 = "5001800US3604"
320
- NY_05 = "5001800US3605"
321
- NY_06 = "5001800US3606"
322
- NY_07 = "5001800US3607"
323
- NY_08 = "5001800US3608"
324
- NY_09 = "5001800US3609"
325
- NY_10 = "5001800US3610"
326
- NY_11 = "5001800US3611"
327
- NY_12 = "5001800US3612"
328
- NY_13 = "5001800US3613"
329
- NY_14 = "5001800US3614"
330
- NY_15 = "5001800US3615"
331
- NY_16 = "5001800US3616"
332
- NY_17 = "5001800US3617"
333
- NY_18 = "5001800US3618"
334
- NY_19 = "5001800US3619"
335
- NY_20 = "5001800US3620"
336
- NY_21 = "5001800US3621"
337
- NY_22 = "5001800US3622"
338
- NY_23 = "5001800US3623"
339
- NY_24 = "5001800US3624"
340
- NY_25 = "5001800US3625"
341
- NY_26 = "5001800US3626"
342
- NC_01 = "5001800US3701"
343
- NC_02 = "5001800US3702"
344
- NC_03 = "5001800US3703"
345
- NC_04 = "5001800US3704"
346
- NC_05 = "5001800US3705"
347
- NC_06 = "5001800US3706"
348
- NC_07 = "5001800US3707"
349
- NC_08 = "5001800US3708"
350
- NC_09 = "5001800US3709"
351
- NC_10 = "5001800US3710"
352
- NC_11 = "5001800US3711"
353
- NC_12 = "5001800US3712"
354
- NC_13 = "5001800US3713"
355
- NC_14 = "5001800US3714"
356
- ND_01 = "5001800US3800"
357
- OH_01 = "5001800US3901"
358
- OH_02 = "5001800US3902"
359
- OH_03 = "5001800US3903"
360
- OH_04 = "5001800US3904"
361
- OH_05 = "5001800US3905"
362
- OH_06 = "5001800US3906"
363
- OH_07 = "5001800US3907"
364
- OH_08 = "5001800US3908"
365
- OH_09 = "5001800US3909"
366
- OH_10 = "5001800US3910"
367
- OH_11 = "5001800US3911"
368
- OH_12 = "5001800US3912"
369
- OH_13 = "5001800US3913"
370
- OH_14 = "5001800US3914"
371
- OH_15 = "5001800US3915"
372
- OK_01 = "5001800US4001"
373
- OK_02 = "5001800US4002"
374
- OK_03 = "5001800US4003"
375
- OK_04 = "5001800US4004"
376
- OK_05 = "5001800US4005"
377
- OR_01 = "5001800US4101"
378
- OR_02 = "5001800US4102"
379
- OR_03 = "5001800US4103"
380
- OR_04 = "5001800US4104"
381
- OR_05 = "5001800US4105"
382
- OR_06 = "5001800US4106"
383
- PA_01 = "5001800US4201"
384
- PA_02 = "5001800US4202"
385
- PA_03 = "5001800US4203"
386
- PA_04 = "5001800US4204"
387
- PA_05 = "5001800US4205"
388
- PA_06 = "5001800US4206"
389
- PA_07 = "5001800US4207"
390
- PA_08 = "5001800US4208"
391
- PA_09 = "5001800US4209"
392
- PA_10 = "5001800US4210"
393
- PA_11 = "5001800US4211"
394
- PA_12 = "5001800US4212"
395
- PA_13 = "5001800US4213"
396
- PA_14 = "5001800US4214"
397
- PA_15 = "5001800US4215"
398
- PA_16 = "5001800US4216"
399
- PA_17 = "5001800US4217"
400
- RI_01 = "5001800US4401"
401
- RI_02 = "5001800US4402"
402
- SC_01 = "5001800US4501"
403
- SC_02 = "5001800US4502"
404
- SC_03 = "5001800US4503"
405
- SC_04 = "5001800US4504"
406
- SC_05 = "5001800US4505"
407
- SC_06 = "5001800US4506"
408
- SC_07 = "5001800US4507"
409
- SD_01 = "5001800US4600"
410
- TN_01 = "5001800US4701"
411
- TN_02 = "5001800US4702"
412
- TN_03 = "5001800US4703"
413
- TN_04 = "5001800US4704"
414
- TN_05 = "5001800US4705"
415
- TN_06 = "5001800US4706"
416
- TN_07 = "5001800US4707"
417
- TN_08 = "5001800US4708"
418
- TN_09 = "5001800US4709"
419
- TX_01 = "5001800US4801"
420
- TX_02 = "5001800US4802"
421
- TX_03 = "5001800US4803"
422
- TX_04 = "5001800US4804"
423
- TX_05 = "5001800US4805"
424
- TX_06 = "5001800US4806"
425
- TX_07 = "5001800US4807"
426
- TX_08 = "5001800US4808"
427
- TX_09 = "5001800US4809"
428
- TX_10 = "5001800US4810"
429
- TX_11 = "5001800US4811"
430
- TX_12 = "5001800US4812"
431
- TX_13 = "5001800US4813"
432
- TX_14 = "5001800US4814"
433
- TX_15 = "5001800US4815"
434
- TX_16 = "5001800US4816"
435
- TX_17 = "5001800US4817"
436
- TX_18 = "5001800US4818"
437
- TX_19 = "5001800US4819"
438
- TX_20 = "5001800US4820"
439
- TX_21 = "5001800US4821"
440
- TX_22 = "5001800US4822"
441
- TX_23 = "5001800US4823"
442
- TX_24 = "5001800US4824"
443
- TX_25 = "5001800US4825"
444
- TX_26 = "5001800US4826"
445
- TX_27 = "5001800US4827"
446
- TX_28 = "5001800US4828"
447
- TX_29 = "5001800US4829"
448
- TX_30 = "5001800US4830"
449
- TX_31 = "5001800US4831"
450
- TX_32 = "5001800US4832"
451
- TX_33 = "5001800US4833"
452
- TX_34 = "5001800US4834"
453
- TX_35 = "5001800US4835"
454
- TX_36 = "5001800US4836"
455
- TX_37 = "5001800US4837"
456
- TX_38 = "5001800US4838"
457
- UT_01 = "5001800US4901"
458
- UT_02 = "5001800US4902"
459
- UT_03 = "5001800US4903"
460
- UT_04 = "5001800US4904"
461
- VT_01 = "5001800US5000"
462
- VA_01 = "5001800US5101"
463
- VA_02 = "5001800US5102"
464
- VA_03 = "5001800US5103"
465
- VA_04 = "5001800US5104"
466
- VA_05 = "5001800US5105"
467
- VA_06 = "5001800US5106"
468
- VA_07 = "5001800US5107"
469
- VA_08 = "5001800US5108"
470
- VA_09 = "5001800US5109"
471
- VA_10 = "5001800US5110"
472
- VA_11 = "5001800US5111"
473
- WA_01 = "5001800US5301"
474
- WA_02 = "5001800US5302"
475
- WA_03 = "5001800US5303"
476
- WA_04 = "5001800US5304"
477
- WA_05 = "5001800US5305"
478
- WA_06 = "5001800US5306"
479
- WA_07 = "5001800US5307"
480
- WA_08 = "5001800US5308"
481
- WA_09 = "5001800US5309"
482
- WA_10 = "5001800US5310"
483
- WV_01 = "5001800US5401"
484
- WV_02 = "5001800US5402"
485
- WI_01 = "5001800US5501"
486
- WI_02 = "5001800US5502"
487
- WI_03 = "5001800US5503"
488
- WI_04 = "5001800US5504"
489
- WI_05 = "5001800US5505"
490
- WI_06 = "5001800US5506"
491
- WI_07 = "5001800US5507"
492
- WI_08 = "5001800US5508"
493
- WY_01 = "5001800US5600"
494
-
495
- def get_hierarchical_codes(self) -> List[str]:
496
- """
497
- Returns all applicable UCGID codes for this enum value in hierarchical order.
498
-
499
- Returns:
500
- List of UCGID codes from most specific to least specific
501
-
502
- Examples:
503
- UCGID.CA_23.get_hierarchical_codes() -> ["5001800US0623", "0400000US06", "0100000US"]
504
- UCGID.CA.get_hierarchical_codes() -> ["0400000US06", "0100000US"]
505
- UCGID.US.get_hierarchical_codes() -> ["0100000US"]
506
- """
507
- code = self.value
508
- codes_list = [code]
509
-
510
- # If it's a district code (Congressional District format: 5001800US + state + district)
511
- if code.startswith("5001800US"):
512
- # Extract state code from district code
513
- state_code_num = code[9:11] # Extract 2-digit state code
514
- state_code = f"0400000US{state_code_num}"
515
-
516
- # Add state code if it exists in the enum
517
- for state_enum in UCGID:
518
- if state_enum.value == state_code:
519
- codes_list.append(state_code)
520
- break
521
-
522
- # Add US code
523
- codes_list.append("0100000US")
524
-
525
- # If it's a state code (State format: 0400000US + state code)
526
- elif code.startswith("0400000US"):
527
- # Add US code
528
- codes_list.append("0100000US")
529
-
530
- # If it's already the US code, return as-is
531
- # (US code: "0100000US")
532
-
533
- return codes_list
534
-
535
- def matches_hierarchy(self, target_code: str) -> bool:
536
- """
537
- Check if this UCGID code matches a target code in the hierarchy.
538
-
539
- Args:
540
- target_code: The target code to match against
541
-
542
- Returns:
543
- True if this code belongs to the target code's hierarchy
544
-
545
- Examples:
546
- UCGID.CA_23.matches_hierarchy("0400000US06") -> True (CA_23 is in CA)
547
- UCGID.CA_23.matches_hierarchy("0100000US") -> True (CA_23 is in US)
548
- UCGID.CA.matches_hierarchy("5001800US0623") -> False (CA is not CA_23)
549
- """
550
- hierarchical_codes = self.get_hierarchical_codes()
551
- return target_code in hierarchical_codes
@@ -1,29 +0,0 @@
1
- from policyengine_us.model_api import *
2
- from policyengine_us.variables.household.demographic.geographic.ucgid.ucgid_enum import (
3
- UCGID,
4
- )
5
-
6
-
7
- class ucgid_str(Variable):
8
- value_type = str
9
- entity = Household
10
- label = "UCGID (string)"
11
- documentation = "UCGID variable, stored as a string"
12
- definition_period = YEAR
13
-
14
- def formula(household, period, parameters):
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)