44"""
55
66import numpy as np
7+ import pandas as pd
78
89from policyengine_us_data .calibration .source_impute import (
910 ACS_IMPUTED_VARIABLES ,
2122 _person_state_fips ,
2223 impute_source_variables ,
2324)
25+ from policyengine_us_data .datasets .cps .tipped_occupation import (
26+ derive_any_treasury_tipped_occupation_code ,
27+ derive_is_tipped_occupation ,
28+ )
2429from policyengine_us_data .datasets .org import ORG_IMPUTED_VARIABLES
2530
2631
@@ -43,6 +48,9 @@ def _make_data_dict(n_persons=20, time_period=2024):
4348 "employment_income" : {
4449 time_period : rng .uniform (0 , 100000 , n_persons ).astype (np .float32 ),
4550 },
51+ "treasury_tipped_occupation_code" : {
52+ time_period : np .zeros (n_persons , dtype = np .int16 ),
53+ },
4654 "rent" : {time_period : np .zeros (n_persons )},
4755 "real_estate_taxes" : {time_period : np .zeros (n_persons )},
4856 "tip_income" : {time_period : np .zeros (n_persons )},
@@ -100,6 +108,9 @@ def test_acs_uses_state(self):
100108 def test_sipp_tips_has_income (self ):
101109 assert "employment_income" in SIPP_TIPS_PREDICTORS
102110
111+ def test_sipp_tips_uses_tipped_occupation_status (self ):
112+ assert "is_tipped_occupation" in SIPP_TIPS_PREDICTORS
113+
103114 def test_sipp_assets_has_income (self ):
104115 assert "employment_income" in SIPP_ASSETS_PREDICTORS
105116
@@ -228,3 +239,19 @@ def test_impute_org_exists(self):
228239
229240 def test_impute_scf_exists (self ):
230241 assert callable (_impute_scf )
242+
243+
244+ class TestTippedOccupationHelpers :
245+ def test_derive_any_treasury_tipped_occupation_code (self ):
246+ occupations = pd .DataFrame (
247+ {
248+ "TJB1_OCC" : [4040 , 1021 , np .nan ],
249+ "TJB2_OCC" : [np .nan , 4110 , 9620 ],
250+ }
251+ )
252+ derived = derive_any_treasury_tipped_occupation_code (occupations )
253+ np .testing .assert_array_equal (derived , np .array ([101 , 102 , 809 ]))
254+
255+ def test_derive_is_tipped_occupation (self ):
256+ derived = derive_is_tipped_occupation (np .array ([0 , 101 , 809 ]))
257+ np .testing .assert_array_equal (derived , np .array ([False , True , True ]))
0 commit comments