Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microsimulation.df throws TypeError with some sequences of variables #53

Open
MaxGhenis opened this issue Apr 26, 2022 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@MaxGhenis
Copy link
Contributor

MaxGhenis commented Apr 26, 2022

This works:

from openfisca_us import Microsimulation
sim = Microsimulation()
sim.df(["state_code", "snap_gross_income_fpg_ratio"])

but this doesn't:

sim.df(["snap_gross_income_fpg_ratio", "state_code"])
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[<ipython-input-11-856cb2e0dc06>](https://localhost:8080/#) in <module>()
----> 1 df = sim.df(["snap_gross_income_fpg_ratio", "state_code"])
      2 ca_below_fpl = df[(df.snap_gross_income_fpg_ratio < 1) & (df.state_code == "CA")]
      3 ca_below_fpl

3 frames
[/usr/local/lib/python3.7/dist-packages/openfisca_tools/microsimulation.py](https://localhost:8080/#) in map_to(self, arr, entity, target_entity, how)
    216                 return entity_pop.project(arr)
    217             if how == "mean":
--> 218                 return entity_pop.project(arr / entity_pop.nb_persons())
    219         elif entity == target_entity:
    220             return arr

TypeError: ufunc 'true_divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

state_code is a household-level string, snap_gross_income_fpg_ratio is a spmu-level float.

@MaxGhenis MaxGhenis added the bug Something isn't working label Apr 26, 2022
@nikhilwoodruff
Copy link
Contributor

OK, so this is because the spm_unit -> household mapping works for the string type, but not the other way around. Will need some logic added to the map_to function.

@nikhilwoodruff nikhilwoodruff self-assigned this Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants