Skip to content

Commit

Permalink
Fixed - "None" in BF RR was converted to NaN in pandas
Browse files Browse the repository at this point in the history
  • Loading branch information
wptharindu committed Mar 18, 2024
1 parent 5c09bf0 commit 4295089
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
Binary file modified inputs/en/demo_national_input.xlsx
Binary file not shown.
10 changes: 9 additions & 1 deletion nutrition/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def get_risk_dist(self):
# self.calcscache.write_row('Nutritional status distribution', 14, 2, anaem[:])

# for age, prev in anaem.items(): # Should work with commented out code above
for age, prev in anaem.iteritems():
for age, prev in anaem.items():
self.risk_dist[_("Anaemia")][age] = dict()
self.risk_dist[_("Anaemia")][age][_("Anaemic")] = prev
self.risk_dist[_("Anaemia")][age][_("Not anaemic")] = 1.0 - prev
Expand Down Expand Up @@ -625,6 +625,8 @@ def make_dict2(self, mydict):
for condCat in mydict[age].keys():
cond = condCat[0]
cat = condCat[1]
if type(cat) == float:
cat = "None"
if res_dict[age].get(cat) is None:
res_dict[age][cat] = dict() # CK TEST
res_dict[age][cat][cond] = mydict[age][condCat]
Expand All @@ -639,6 +641,8 @@ def make_dict3(self, mydict):
res_dict[age] = sc.odict()
for condCat in mydict[age].keys():
cat = condCat[1]
if type(cat) == float:
cat = "None"
if res_dict[age].get(cat) is None:
res_dict[age][cat] = mydict[age][condCat]
return res_dict
Expand Down Expand Up @@ -1237,6 +1241,8 @@ def make_dict2(self, mydict):
for condCat in mydict[age].keys():
cond = condCat[0]
cat = condCat[1]
if type(cat) == float:
cat = "None"
if res_dict[age].get(cat) is None:
res_dict[age][cat] = dict() # CK TEST
res_dict[age][cat][cond] = mydict[age][condCat]
Expand All @@ -1251,6 +1257,8 @@ def make_dict3(self, mydict):
res_dict[age] = sc.odict()
for condCat in mydict[age].keys():
cat = condCat[1]
if type(cat) == float:
cat = "None"
if res_dict[age].get(cat) is None:
res_dict[age][cat] = mydict[age][condCat]
return res_dict
Expand Down
4 changes: 2 additions & 2 deletions nutrition/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ def _wasting_prev_update(self, age_group):
# If SAM treatment is extended to MAM, then the coverage refers to SAM children, who are only a fraction of MAM children
newcov = min(1, self.annual_unrestr_cov[self.year] * age_group.frac_wasted(_('SAM')) / age_group.frac_wasted(_('MAM')))
newProb = get_new_prob(newcov, probWastedIfCovered, probWastedIfNotCovered)
print(self.year, age_group.age, newcov, probWastedIfCovered, newProb, oldProb,
sc.safedivide(oldProb - newProb, oldProb, default=0.0), probWastedIfCovered - probWastedIfNotCovered)
# print(self.year, age_group.age, newcov, probWastedIfCovered, newProb, oldProb,
# sc.safedivide(oldProb - newProb, oldProb, default=0.0), probWastedIfCovered - probWastedIfNotCovered)
else:
newcov = self.annual_unrestr_cov[self.year]
newProb = get_new_prob(newcov, probWastedIfCovered, probWastedIfNotCovered)
Expand Down
Binary file modified tests/scen_results_test.xlsx
Binary file not shown.
Binary file modified tests/test.prj
Binary file not shown.
6 changes: 3 additions & 3 deletions tests/testdemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import nutrition.ui as nu

do_plot = True
run_scen = False
run_optim = True
run_geo = False
run_scen = True
run_optim = False
run_geo = True

P = nu.demo(scens=run_scen, optims=run_optim, geos=run_geo)

Expand Down

0 comments on commit 4295089

Please sign in to comment.