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.

@@ -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
- assert len(hierarchical_codes) == 1
54
- assert hierarchical_codes[0] == "0100000US"
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
- # 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)
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
- # For non-dataset simulations, try to derive from state_code
27
- if not simulation.is_over_dataset:
28
- state_code = household("state_code", period)
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
- # 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
- }
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
- # 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
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
- return result
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
- return household("ucgid", period).decode_to_str()
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: policyengine-us
3
- Version: 1.365.0
3
+ Version: 1.365.1
4
4
  Summary: Add your description here.
5
5
  Author-email: PolicyEngine <hello@policyengine.org>
6
6
  License-File: LICENSE
@@ -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=_QBrBgX072aY-G1z7UwwNe_1pIUT9SfDMrNUhkPU-B4,2166
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=RX4zSK6mqUoI10Jhe8XSDhrG-H0qOv3zmKMHeSl-TQY,3270
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=ngH3tnYb6m96he1_Cj2dPtyc8nFDOsqlbjGOmh4c79A,335
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.0.dist-info/METADATA,sha256=DQE2dHq4VJDvHfFPlYb1VuGGPavQDv6ZmYNVN0UP1uM,1693
8240
- policyengine_us-1.365.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
8241
- policyengine_us-1.365.0.dist-info/entry_points.txt,sha256=MLaqNyNTbReALyKNkde85VkuFFpdPWAcy8VRG1mjczc,57
8242
- policyengine_us-1.365.0.dist-info/licenses/LICENSE,sha256=2N5ReRelkdqkR9a-KP-y-shmcD5P62XoYiG-miLTAzo,34519
8243
- policyengine_us-1.365.0.dist-info/RECORD,,
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,,