policyengine-us 1.351.5__py3-none-any.whl → 1.352.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.

@@ -0,0 +1,58 @@
1
+ """
2
+ Test script demonstrating UCGID hierarchical functionality.
3
+ """
4
+
5
+ from policyengine_us import Microsimulation
6
+ from policyengine_us.variables.household.demographic.geographic.ucgid.ucgid_enum import (
7
+ UCGID,
8
+ )
9
+
10
+
11
+ class TestUCGIDHierarchical:
12
+ """Test class for UCGID hierarchical functionality."""
13
+
14
+ def test_ucgid_enum_hierarchical_methods(self):
15
+ """Test the hierarchical methods on UCGID enum values directly."""
16
+ print("\n=== Testing UCGID Enum Hierarchical Methods ===")
17
+
18
+ # Test Congressional District (CA_23)
19
+ ca_23 = UCGID.CA_23
20
+ ca_23_codes = ca_23.get_hierarchical_codes()
21
+ print(f"CA_23 hierarchical codes: {ca_23_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
+ print(f"CA hierarchical codes: {ca_codes}")
28
+ assert ca_codes == ["0400000US06", "0100000US"]
29
+
30
+ # Test US
31
+ us = UCGID.US
32
+ us_codes = us.get_hierarchical_codes()
33
+ print(f"US hierarchical codes: {us_codes}")
34
+ assert us_codes == ["0100000US"]
35
+
36
+ # Test hierarchy matching
37
+ assert ca_23.matches_hierarchy("0400000US06") == True
38
+ assert ca_23.matches_hierarchy("0100000US") == True
39
+ assert ca.matches_hierarchy("5001800US0623") == False
40
+
41
+ def test_ucgid_simulation_usage(self):
42
+ """Test how UCGID is used in a PolicyEngine simulation."""
43
+ simulation = Microsimulation()
44
+ ucgid_values = simulation.calculate("ucgid", "2024")
45
+
46
+ # The UCGID value should be a string (enum name)
47
+ ucgid_string = ucgid_values.iloc[0] # First household
48
+ assert type(ucgid_string) == str
49
+
50
+ # Convert the string back to enum to access hierarchical methods
51
+ ucgid_enum = UCGID[ucgid_string]
52
+ hierarchical_codes = ucgid_enum.get_hierarchical_codes()
53
+ assert len(hierarchical_codes) == 1
54
+ assert hierarchical_codes[0] == "0100000US"
55
+
56
+ # Test hierarchy matching in simulation context
57
+ is_in_us = ucgid_enum.matches_hierarchy("0100000US")
58
+ assert is_in_us == True
@@ -0,0 +1,97 @@
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
+ # If we're running over a dataset and UCGID is provided, it should be used directly
24
+ # (This is handled automatically by the simulation framework)
25
+
26
+ # For non-dataset simulations, try to derive from state_code
27
+ if not simulation.is_over_dataset:
28
+ state_code = household("state_code", period)
29
+
30
+ # Map state codes to UCGID state values
31
+ state_mapping = {
32
+ "AL": UCGID.AL,
33
+ "AK": UCGID.AK,
34
+ "AZ": UCGID.AZ,
35
+ "AR": UCGID.AR,
36
+ "CA": UCGID.CA,
37
+ "CO": UCGID.CO,
38
+ "CT": UCGID.CT,
39
+ "DE": UCGID.DE,
40
+ "DC": UCGID.DC,
41
+ "FL": UCGID.FL,
42
+ "GA": UCGID.GA,
43
+ "HI": UCGID.HI,
44
+ "ID": UCGID.ID,
45
+ "IL": UCGID.IL,
46
+ "IN": UCGID.IN,
47
+ "IA": UCGID.IA,
48
+ "KS": UCGID.KS,
49
+ "KY": UCGID.KY,
50
+ "LA": UCGID.LA,
51
+ "ME": UCGID.ME,
52
+ "MD": UCGID.MD,
53
+ "MA": UCGID.MA,
54
+ "MI": UCGID.MI,
55
+ "MN": UCGID.MN,
56
+ "MS": UCGID.MS,
57
+ "MO": UCGID.MO,
58
+ "MT": UCGID.MT,
59
+ "NE": UCGID.NE,
60
+ "NV": UCGID.NV,
61
+ "NH": UCGID.NH,
62
+ "NJ": UCGID.NJ,
63
+ "NM": UCGID.NM,
64
+ "NY": UCGID.NY,
65
+ "NC": UCGID.NC,
66
+ "ND": UCGID.ND,
67
+ "OH": UCGID.OH,
68
+ "OK": UCGID.OK,
69
+ "OR": UCGID.OR,
70
+ "PA": UCGID.PA,
71
+ "RI": UCGID.RI,
72
+ "SC": UCGID.SC,
73
+ "SD": UCGID.SD,
74
+ "TN": UCGID.TN,
75
+ "TX": UCGID.TX,
76
+ "UT": UCGID.UT,
77
+ "VT": UCGID.VT,
78
+ "VA": UCGID.VA,
79
+ "WA": UCGID.WA,
80
+ "WV": UCGID.WV,
81
+ "WI": UCGID.WI,
82
+ "WY": UCGID.WY,
83
+ }
84
+
85
+ # Convert state codes to UCGID values
86
+ result = np.empty(len(state_code), dtype=object)
87
+ for i, code in enumerate(state_code):
88
+ state_str = str(code) if hasattr(code, "__str__") else code
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
95
+
96
+ # Default fallback
97
+ return np.full(household.count, UCGID.US, dtype=object)
@@ -0,0 +1,551 @@
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
@@ -0,0 +1,12 @@
1
+ from policyengine_us.model_api import *
2
+
3
+
4
+ class ucgid_str(Variable):
5
+ value_type = str
6
+ entity = Household
7
+ label = "UCGID (string)"
8
+ documentation = "UCGID variable, stored as a string"
9
+ definition_period = YEAR
10
+
11
+ def formula(household, period, parameters):
12
+ return household("ucgid", period).decode_to_str()
@@ -0,0 +1,9 @@
1
+ from policyengine_us.model_api import *
2
+
3
+
4
+ class household_count(Variable):
5
+ value_type = float
6
+ entity = Household
7
+ label = "Households represented"
8
+ definition_period = YEAR
9
+ default_value = 1.0
@@ -1,7 +1,7 @@
1
1
  from policyengine_us.model_api import *
2
2
 
3
3
 
4
- class people(Variable):
4
+ class person_count(Variable):
5
5
  value_type = float
6
6
  entity = Person
7
7
  label = "People represented"
@@ -0,0 +1,9 @@
1
+ from policyengine_us.model_api import *
2
+
3
+
4
+ class spm_unit_count(Variable):
5
+ value_type = float
6
+ entity = SPMUnit
7
+ label = "SPM units represented"
8
+ definition_period = YEAR
9
+ default_value = 1.0
@@ -0,0 +1,9 @@
1
+ from policyengine_us.model_api import *
2
+
3
+
4
+ class tax_unit_count(Variable):
5
+ value_type = float
6
+ entity = TaxUnit
7
+ label = "Tax units represented"
8
+ definition_period = YEAR
9
+ default_value = 1.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: policyengine-us
3
- Version: 1.351.5
3
+ Version: 1.352.1
4
4
  Summary: Add your description here.
5
5
  Author-email: PolicyEngine <hello@policyengine.org>
6
6
  License-File: LICENSE
@@ -5075,6 +5075,7 @@ policyengine_us/tests/policy/contrib/ubi_center/flat_tax.yaml,sha256=O6krfJ2rovW
5075
5075
  policyengine_us/tests/policy/reform/ctc_expansion.yaml,sha256=soq-LqWwbb7fNQJFphx_1gSc8uDGOhtr-5P93oY2Mpg,1596
5076
5076
  policyengine_us/tests/policy/reform/winship.yaml,sha256=OPfsoZ0NrlPU25hJadZXycrYLaM0wPUGXjBrn6_8gR4,1706
5077
5077
  policyengine_us/tests/utilities/test_load_county_fips_dataset.py,sha256=QAURDL6IMN5gafUOcTri1PUet6khLNZ_Bov6NdW_pMM,4397
5078
+ policyengine_us/tests/utilities/test_ucgid_hierarchical.py,sha256=_QBrBgX072aY-G1z7UwwNe_1pIUT9SfDMrNUhkPU-B4,2166
5078
5079
  policyengine_us/tools/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
5079
5080
  policyengine_us/tools/add_plotly_to_book.py,sha256=8V8jI6ob-FkNamfo7dZfiBsyT9N1uuUl2IFbo3SuG5E,935
5080
5081
  policyengine_us/tools/branched_simulation.py,sha256=oRIM-uiyilcwdFIQfE6-DIRND9bJlf5L-RrGNWzsrnc,1220
@@ -7675,9 +7676,13 @@ policyengine_us/variables/household/demographic/geographic/county/county_enum.py
7675
7676
  policyengine_us/variables/household/demographic/geographic/county/county_str.py,sha256=UDWJ8YqH4Ef_JTscy8LMwLAMQ_o-Zan13hziZBY3XPs,339
7676
7677
  policyengine_us/variables/household/demographic/geographic/state/average_home_energy_use_in_state.py,sha256=aaGYAXLU7tsx-A9NW4nyLij5J5mp0WTRXsyObngekvY,319
7677
7678
  policyengine_us/variables/household/demographic/geographic/state/in_state.py,sha256=o3ksZCOHtlJ1JGHIXAPlqcs5-rVbTgOCcDdN1-fYqmA,551
7679
+ policyengine_us/variables/household/demographic/geographic/ucgid/ucgid.py,sha256=RX4zSK6mqUoI10Jhe8XSDhrG-H0qOv3zmKMHeSl-TQY,3270
7680
+ policyengine_us/variables/household/demographic/geographic/ucgid/ucgid_enum.py,sha256=dkeusTBI1j4xAGmRFkfSsyT3Hq5gHZwRUkSeISeNbx0,15636
7681
+ policyengine_us/variables/household/demographic/geographic/ucgid/ucgid_str.py,sha256=ngH3tnYb6m96he1_Cj2dPtyc8nFDOsqlbjGOmh4c79A,335
7678
7682
  policyengine_us/variables/household/demographic/geographic/zip_code/three_digit_zip_code.py,sha256=7q0FQRahTOINiK2vlAyHEa5xIKowM5Kgl60-kR3ZuWU,426
7679
7683
  policyengine_us/variables/household/demographic/geographic/zip_code/zip_code.py,sha256=PZiLb84BgKQ_Suvd6iUiEnzySu3Vtiv8FOlfB4rnagQ,1691
7680
7684
  policyengine_us/variables/household/demographic/household/bedrooms.py,sha256=4ltdIRLdmeuTKAskn4pdgxZuxEE-4rz0ffPnIKobc-o,164
7685
+ policyengine_us/variables/household/demographic/household/household_count.py,sha256=f6dIPWyCtWlZ-qTSCPDrzCfINSzoJOE5Tw1ynBKYfGA,211
7681
7686
  policyengine_us/variables/household/demographic/household/household_size.py,sha256=DR5PS9bylHlPphL3-Y0ySR4E0cavAf6qyMpNJG2N3ig,263
7682
7687
  policyengine_us/variables/household/demographic/household/household_vehicle_value.py,sha256=2iIkkdx0bddROen2yC5HVPzLZq7FswPYfQLQdSOiYBM,197
7683
7688
  policyengine_us/variables/household/demographic/household/household_vehicles_owned.py,sha256=TcoVryjJbojB6BQNBauYNAPaWCoOgtyNo-QIwc7tW7g,186
@@ -7755,7 +7760,7 @@ policyengine_us/variables/household/demographic/person/is_surviving_child_of_dis
7755
7760
  policyengine_us/variables/household/demographic/person/is_surviving_spouse_of_disabled_veteran.py,sha256=xtJ7ZoD0EoTocweoQHzacknU-VshqvKn_LusCc95jkE,221
7756
7761
  policyengine_us/variables/household/demographic/person/is_veteran.py,sha256=IWRoK5OVD41DBVymQlxJefVHSUPhWXqtNOokZX4hSVc,522
7757
7762
  policyengine_us/variables/household/demographic/person/own_children_in_household.py,sha256=SFulI2WcpX_VeCugBYR-riI8FRXAS_Fm-LnZHwiEEsY,214
7758
- policyengine_us/variables/household/demographic/person/people.py,sha256=EYLp25usXjNx_dcZKhjHOJxKKStRZXfxuQeYWDTCZL0,195
7763
+ policyengine_us/variables/household/demographic/person/person_count.py,sha256=Ai3jDNpodfnAf2GVaPYoo0KUUXUwP-gTy9cPmDS31h8,201
7759
7764
  policyengine_us/variables/household/demographic/person/race.py,sha256=5mtRUZZ9_0KF7sabvlW-FvA5MgL3NdqufgxAhXzVjtI,924
7760
7765
  policyengine_us/variables/household/demographic/person/receives_or_needs_protective_services.py,sha256=F4DN9e1-6NVQaZeRJjoITW3EnYP2YGeQWTlpTcTvmDc,227
7761
7766
  policyengine_us/variables/household/demographic/person/retired_from_federal_government.py,sha256=Ouj952ujVRsfJ9zp1gK3z6txnrZrfvAtm6nKY0lUbwI,265
@@ -7769,6 +7774,7 @@ policyengine_us/variables/household/demographic/person/years_in_military.py,sha2
7769
7774
  policyengine_us/variables/household/demographic/person/postpartum/count_days_postpartum.py,sha256=d8oTm11yv8MxuGk7pYTkmYAmUc0fGYY2znnKeTtMIVE,634
7770
7775
  policyengine_us/variables/household/demographic/person/postpartum/under_12_months_postpartum.py,sha256=olSjQDrPSoF2ReoOJdvQGxrQtC_ssXOlqjEWcUr5jLE,198
7771
7776
  policyengine_us/variables/household/demographic/person/postpartum/under_60_days_postpartum.py,sha256=CnyxJaqQlpeFH210qye9ZOtLci39f9Tao-KTZILmHfQ,209
7777
+ policyengine_us/variables/household/demographic/spm_unit/spm_unit_count.py,sha256=7EG_PisVfHK0SZu7FdfR7o5eU6Y_sq5zc3cWepVHTEE,207
7772
7778
  policyengine_us/variables/household/demographic/spm_unit/spm_unit_count_adults.py,sha256=mZ6kIBg5O5bW4ZTmRHCVaVMBLXy-q8z_yKN2vy4FWUg,299
7773
7779
  policyengine_us/variables/household/demographic/spm_unit/spm_unit_count_children.py,sha256=6MRJfySnAcwSf9BpMp3CtAeEBGCiVi4MxFNMlhN6Tso,213
7774
7780
  policyengine_us/variables/household/demographic/spm_unit/spm_unit_id.py,sha256=DV_RH3Mm84fGK-ZFmpH6vDeBA2WJxd-tTvgNXg1i0BE,302
@@ -7802,6 +7808,7 @@ policyengine_us/variables/household/demographic/tax_unit/spouse_separate_tax_uni
7802
7808
  policyengine_us/variables/household/demographic/tax_unit/surviving_spouse_eligible.py,sha256=7BKjhsg3GkEQ4ZtYofXdR2RQ3EArcytBMxAS97uhPCs,942
7803
7809
  policyengine_us/variables/household/demographic/tax_unit/tax_unit_child_dependents.py,sha256=m2xdtEuxi_hPTyRINC3ePcHxnHPLNgGQkY6JUUVbjCw,248
7804
7810
  policyengine_us/variables/household/demographic/tax_unit/tax_unit_children.py,sha256=717HdVz20j9lz2G71TMqjLbkeocpv13-oPHV2KdlarA,309
7811
+ policyengine_us/variables/household/demographic/tax_unit/tax_unit_count.py,sha256=GILRn5wc981vvLysMN-H6NCpA3lCYn6LpMUz_I_FEng,207
7805
7812
  policyengine_us/variables/household/demographic/tax_unit/tax_unit_dependents.py,sha256=Z3nskCJGmT55MHqscvSaPiGMQsVeW6J2ebqtAAI6avY,239
7806
7813
  policyengine_us/variables/household/demographic/tax_unit/tax_unit_grandparents.py,sha256=XXi3tXRm0ba4q2JmCrnKc5SnrAJaRXBeYiPQyWxoyGI,255
7807
7814
  policyengine_us/variables/household/demographic/tax_unit/tax_unit_household_id.py,sha256=1bth3yo2dbgyqWHQ01AQVZDlDcbLhMQ6TGdd3lTaoIU,384
@@ -8119,8 +8126,8 @@ policyengine_us/variables/input/farm_income.py,sha256=BEKxYmHNNnWJAAvULl5qZJigy5
8119
8126
  policyengine_us/variables/input/geography.py,sha256=XmBlgXhzBoLRKk6R8taVZHqUw1eU8MbNeGS9iJ7_l44,4506
8120
8127
  policyengine_us/variables/input/self_employment_income.py,sha256=PwsGz8R4lRikKWUYOhsC0qosNNLXq4f5SQmfw4S3mk8,511
8121
8128
  policyengine_us/variables/input/self_employment_income_before_lsr.py,sha256=E8fcX9Nlyqz8dziHhQv_euutdmoIwFMMWePUwbbwv_w,379
8122
- policyengine_us-1.351.5.dist-info/METADATA,sha256=G7kIwoeS_BGXfygItInB6H8iTnl5VtB_6jtHffJJnt4,1693
8123
- policyengine_us-1.351.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8124
- policyengine_us-1.351.5.dist-info/entry_points.txt,sha256=MLaqNyNTbReALyKNkde85VkuFFpdPWAcy8VRG1mjczc,57
8125
- policyengine_us-1.351.5.dist-info/licenses/LICENSE,sha256=2N5ReRelkdqkR9a-KP-y-shmcD5P62XoYiG-miLTAzo,34519
8126
- policyengine_us-1.351.5.dist-info/RECORD,,
8129
+ policyengine_us-1.352.1.dist-info/METADATA,sha256=yJyf7tovGURTQtdT0lcTZ98tk5inDHvHYm4URLxNYOM,1693
8130
+ policyengine_us-1.352.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8131
+ policyengine_us-1.352.1.dist-info/entry_points.txt,sha256=MLaqNyNTbReALyKNkde85VkuFFpdPWAcy8VRG1mjczc,57
8132
+ policyengine_us-1.352.1.dist-info/licenses/LICENSE,sha256=2N5ReRelkdqkR9a-KP-y-shmcD5P62XoYiG-miLTAzo,34519
8133
+ policyengine_us-1.352.1.dist-info/RECORD,,