44"""
55
66import numpy as np
7+ import pandas as pd
78
89from policyengine_us_data .calibration .source_impute import (
910 ACS_IMPUTED_VARIABLES ,
2021 _person_state_fips ,
2122 impute_source_variables ,
2223)
24+ from policyengine_us_data .datasets .cps .tipped_occupation import (
25+ derive_any_treasury_tipped_occupation_code ,
26+ derive_is_tipped_occupation ,
27+ )
2328
2429
2530def _make_data_dict (n_persons = 20 , time_period = 2024 ):
@@ -41,6 +46,9 @@ def _make_data_dict(n_persons=20, time_period=2024):
4146 "employment_income" : {
4247 time_period : rng .uniform (0 , 100000 , n_persons ).astype (np .float32 ),
4348 },
49+ "treasury_tipped_occupation_code" : {
50+ time_period : np .zeros (n_persons , dtype = np .int16 ),
51+ },
4452 "rent" : {time_period : np .zeros (n_persons )},
4553 "real_estate_taxes" : {time_period : np .zeros (n_persons )},
4654 "tip_income" : {time_period : np .zeros (n_persons )},
@@ -85,6 +93,9 @@ def test_acs_uses_state(self):
8593 def test_sipp_tips_has_income (self ):
8694 assert "employment_income" in SIPP_TIPS_PREDICTORS
8795
96+ def test_sipp_tips_uses_tipped_occupation_status (self ):
97+ assert "is_tipped_occupation" in SIPP_TIPS_PREDICTORS
98+
8899 def test_sipp_assets_has_income (self ):
89100 assert "employment_income" in SIPP_ASSETS_PREDICTORS
90101
@@ -205,3 +216,19 @@ def test_impute_sipp_exists(self):
205216
206217 def test_impute_scf_exists (self ):
207218 assert callable (_impute_scf )
219+
220+
221+ class TestTippedOccupationHelpers :
222+ def test_derive_any_treasury_tipped_occupation_code (self ):
223+ occupations = pd .DataFrame (
224+ {
225+ "TJB1_OCC" : [4040 , 1021 , np .nan ],
226+ "TJB2_OCC" : [np .nan , 4110 , 9620 ],
227+ }
228+ )
229+ derived = derive_any_treasury_tipped_occupation_code (occupations )
230+ np .testing .assert_array_equal (derived , np .array ([101 , 102 , 809 ]))
231+
232+ def test_derive_is_tipped_occupation (self ):
233+ derived = derive_is_tipped_occupation (np .array ([0 , 101 , 809 ]))
234+ np .testing .assert_array_equal (derived , np .array ([False , True , True ]))
0 commit comments