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

@@ -63,9 +63,6 @@ from .ctc import (
63
63
  create_ctc_older_child_supplement_reform,
64
64
  create_ctc_additional_bracket_reform,
65
65
  )
66
- from .second_earner import (
67
- create_second_earner_tax_reform,
68
- )
69
66
  from .snap import (
70
67
  create_abolish_snap_deductions_reform,
71
68
  create_abolish_snap_net_income_test_reform,
@@ -192,9 +189,6 @@ def create_structural_reforms_from_parameters(parameters, period):
192
189
  ctc_older_child_supplement = create_ctc_older_child_supplement_reform(
193
190
  parameters, period
194
191
  )
195
- second_earner_tax_reform = create_second_earner_tax_reform(
196
- parameters, period
197
- )
198
192
  abolish_snap_deductions = create_abolish_snap_deductions_reform(
199
193
  parameters, period
200
194
  )
@@ -301,7 +295,6 @@ def create_structural_reforms_from_parameters(parameters, period):
301
295
  salt_phase_out,
302
296
  repeal_state_dependent_exemptions,
303
297
  ctc_older_child_supplement,
304
- second_earner_tax_reform,
305
298
  abolish_snap_deductions,
306
299
  abolish_snap_net_income_test,
307
300
  dc_property_tax_credit,
@@ -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)