diff --git a/fiscalsim_us/variables/gov/hhs/medicaid/eligibility/categories/older_child/is_older_child_for_medicaid.py b/fiscalsim_us/variables/gov/hhs/medicaid/eligibility/categories/older_child/is_older_child_for_medicaid.py index 1b1f40fba..8990d3742 100644 --- a/fiscalsim_us/variables/gov/hhs/medicaid/eligibility/categories/older_child/is_older_child_for_medicaid.py +++ b/fiscalsim_us/variables/gov/hhs/medicaid/eligibility/categories/older_child/is_older_child_for_medicaid.py @@ -1,6 +1,6 @@ +import numpy as np from fiscalsim_us.model_api import * - class is_older_child_for_medicaid(Variable): value_type = bool entity = Person @@ -17,4 +17,22 @@ def formula(person, period, parameters): is_older_child = ma.age_range.calc(age) state = person.household("state_code_str", period) income_limit = ma.income_limit[state] - return is_older_child & (income < income_limit) + + try: + result = is_older_child & (income < income_limit) + return result + except Exception as e: + print(f"Calculation failed: {str(e)}") + print(f"is_older_child: type={type(is_older_child)}, value={is_older_child}") + print(f"income: type={type(income)}, value={income}") + print(f"income_limit: type={type(income_limit)}, value={income_limit}") + + # Convert to numpy arrays and ensure correct types + is_older_child = np.asarray(is_older_child if is_older_child is not None else False).astype(bool) + income = np.asarray(income if income is not None else 0).astype(float) + income_limit = np.asarray(income_limit if income_limit is not None else 0).astype(float) + + # Attempt calculation again + result = is_older_child & (income < income_limit) + print("Calculation succeeded after type conversion") + return result \ No newline at end of file diff --git a/fiscalsim_us/variables/gov/irs/credits/premium_tax_credit/is_ptc_eligible.py b/fiscalsim_us/variables/gov/irs/credits/premium_tax_credit/is_ptc_eligible.py index fa8760398..5e96d15ad 100644 --- a/fiscalsim_us/variables/gov/irs/credits/premium_tax_credit/is_ptc_eligible.py +++ b/fiscalsim_us/variables/gov/irs/credits/premium_tax_credit/is_ptc_eligible.py @@ -1,6 +1,6 @@ +import numpy as np from fiscalsim_us.model_api import * - class is_ptc_eligible(Variable): value_type = bool entity = TaxUnit @@ -15,4 +15,9 @@ def formula(tax_unit, period, parameters): on_marketplace = ( add(tax_unit, period, ["has_marketplace_health_coverage"]) > 0 ) - return on_marketplace & eligibility.calc(income_level) + income_eligible = eligibility.calc(income_level) + + on_marketplace = np.array(on_marketplace, dtype=bool) + income_eligible = np.array(income_eligible, dtype=bool) + + return on_marketplace & income_eligible \ No newline at end of file diff --git a/fiscalsim_us/variables/gov/states/co/ssa/oap/co_oap_eligible.py b/fiscalsim_us/variables/gov/states/co/ssa/oap/co_oap_eligible.py index aeb13aa1c..6bda084f3 100644 --- a/fiscalsim_us/variables/gov/states/co/ssa/oap/co_oap_eligible.py +++ b/fiscalsim_us/variables/gov/states/co/ssa/oap/co_oap_eligible.py @@ -1,4 +1,5 @@ from fiscalsim_us.model_api import * +import numpy as np class co_oap_eligible(Variable): @@ -12,10 +13,23 @@ def formula(person, period, parameters): assets = person("ssi_countable_resources", period) joint_claim = person("ssi_claim_is_joint", period) p = parameters(period).gov.states.co.ssa.oap - asset_limit = where( - joint_claim, p.resources.couple, p.resources.single + + assets = np.array(assets) + joint_claim = np.array(joint_claim, dtype=bool) + + asset_limit = np.where( + joint_claim, + p.resources.couple, + p.resources.single ) + below_asset_limit = assets <= asset_limit + age = person("age", period) in_age_range = p.age_range.calc(age) + + in_age_range = np.array(in_age_range, dtype=bool) + + below_asset_limit = below_asset_limit.astype(bool) + return below_asset_limit & in_age_range diff --git a/fiscalsim_us/variables/gov/states/co/ssa/state_suplement/co_state_supplement_eligible.py b/fiscalsim_us/variables/gov/states/co/ssa/state_suplement/co_state_supplement_eligible.py index d134f9602..68dc49218 100644 --- a/fiscalsim_us/variables/gov/states/co/ssa/state_suplement/co_state_supplement_eligible.py +++ b/fiscalsim_us/variables/gov/states/co/ssa/state_suplement/co_state_supplement_eligible.py @@ -1,5 +1,5 @@ from fiscalsim_us.model_api import * - +import numpy as np class co_state_supplement_eligible(Variable): value_type = bool @@ -12,8 +12,19 @@ def formula(person, period, parameters): ssi_eligible = person("is_ssi_eligible_individual", period) is_disabled = person("is_ssi_disabled", period) is_blind = person("is_blind", period) - disabled_or_blind = is_disabled | is_blind age = person("age", period) p = parameters(period).gov.states.co.ssa.state_supplement + + # Convert to boolean arrays and handle potential None or NaN values + ssi_eligible = np.array(ssi_eligible).astype(bool) + is_disabled = np.array(is_disabled).astype(bool) + is_blind = np.array(is_blind).astype(bool) + + disabled_or_blind = is_disabled | is_blind in_age_range = p.age_range.calc(age) - return disabled_or_blind & ssi_eligible & in_age_range + + # Convert in_age_range to boolean array + in_age_range = np.array(in_age_range).astype(bool) + + # Use bitwise & for the final operation + return disabled_or_blind & ssi_eligible & in_age_range \ No newline at end of file