@@ -43,6 +43,8 @@ def test_add_previous_year_income_closes_raw_cps_handles():
4343 current_person = pd .DataFrame (
4444 {
4545 "PERIDNUM" : [10 , 20 ],
46+ "WSAL_VAL" : [1_100 , 2_100 ],
47+ "SEMP_VAL" : [110 , 210 ],
4648 "I_ERNVAL" : [0 , 0 ],
4749 "I_SEVAL" : [0 , 0 ],
4850 }
@@ -80,6 +82,56 @@ def test_add_previous_year_income_closes_raw_cps_handles():
8082 assert previous_store .closed is True
8183
8284
85+ def test_add_previous_year_income_imputes_unavailable_rows ():
86+ current_person = pd .DataFrame (
87+ {
88+ "PERIDNUM" : [10 , 20 , 30 , 40 , 50 ],
89+ "WSAL_VAL" : [1_100 , 2_100 , 3_100 , 4_100 , - 1 ],
90+ "SEMP_VAL" : [110 , 210 , 310 , 410 , - 9999 ],
91+ "I_ERNVAL" : [0 , 0 , 0 , 0 , 0 ],
92+ "I_SEVAL" : [0 , 0 , 0 , 0 , 0 ],
93+ }
94+ )
95+ previous_person = pd .DataFrame (
96+ {
97+ "PERIDNUM" : [10 , 20 , 30 ],
98+ "WSAL_VAL" : [1_000 , 2_000 , - 9999 ],
99+ "SEMP_VAL" : [100 , - 1 , 300 ],
100+ "I_ERNVAL" : [0 , 0 , 0 ],
101+ "I_SEVAL" : [0 , 0 , 0 ],
102+ }
103+ )
104+
105+ current_store = _FakeStore (current_person )
106+ previous_store = _FakeStore (previous_person )
107+
108+ current_dataset = type ("CurrentDataset" , (_FakeDataset ,), {"store" : current_store })
109+ previous_dataset = type (
110+ "PreviousDataset" , (_FakeDataset ,), {"store" : previous_store }
111+ )
112+
113+ holder = SimpleNamespace (
114+ raw_cps = current_dataset ,
115+ previous_year_raw_cps = previous_dataset ,
116+ )
117+ cps = {}
118+
119+ add_previous_year_income (holder , cps )
120+
121+ np .testing .assert_array_equal (
122+ cps ["employment_income_last_year" ],
123+ [1_000 , 2_100 , 3_100 , 4_100 , 0 ],
124+ )
125+ np .testing .assert_array_equal (
126+ cps ["self_employment_income_last_year" ],
127+ [100 , 210 , 310 , 410 , 0 ],
128+ )
129+ np .testing .assert_array_equal (
130+ cps ["previous_year_income_available" ],
131+ [True , False , False , False , False ],
132+ )
133+
134+
83135def test_add_previous_year_income_opens_hdfstores_read_only (tmp_path , monkeypatch ):
84136 current_path = tmp_path / "current.h5"
85137 previous_path = tmp_path / "previous.h5"
@@ -88,6 +140,8 @@ def test_add_previous_year_income_opens_hdfstores_read_only(tmp_path, monkeypatc
88140 store ["person" ] = pd .DataFrame (
89141 {
90142 "PERIDNUM" : [10 , 20 ],
143+ "WSAL_VAL" : [1_100 , 2_100 ],
144+ "SEMP_VAL" : [110 , 210 ],
91145 "I_ERNVAL" : [0 , 0 ],
92146 "I_SEVAL" : [0 , 0 ],
93147 }
0 commit comments