akelleh / causality

Tools for causal analysis
MIT License
1.06k stars 128 forks source link

TypeError: can only concatenate list (not "dict_keys") to list #54

Closed nickvandewiele closed 6 years ago

nickvandewiele commented 6 years ago

From: https://medium.com/@akelleh/causal-inference-with-pandas-dataframes-fc3e64fce5d

I believe I did this:

pip install git+https://github.com/akelleh/causality.git@c52425a2db16d27780746295ec68752b7986890c --upgrade

X.zplot(x='x', y='y', z={'z1': 'c', 'z2': 'c'}, kind='line', model_type='kernel')


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-c084bc38fd7e> in <module>()
----> 1 X.zplot(x='x', y='y', z={'z1': 'c', 'z2': 'c'}, kind='line', model_type='kernel')

~\Anaconda3\envs\inference\lib\site-packages\causality\analysis\dataframe.py in zplot(self, *args, **kwargs)
      9         if kwargs.get('z', {}):
     10             if kwargs.get('kind') == 'line':
---> 11                 return self._line_zplot(*args, **kwargs)
     12             if kwargs.get('kind') == 'bar':
     13                 return self._bar_zplot(*args, **kwargs)

~\Anaconda3\envs\inference\lib\site-packages\causality\analysis\dataframe.py in _line_zplot(self, *args, **kwargs)
     23 
     24     def _line_zplot(self, *args, **kwargs):
---> 25         model, arg_key = self._get_model(*args, **kwargs)
     26         if arg_key:
     27             del kwargs[arg_key]

~\Anaconda3\envs\inference\lib\site-packages\causality\analysis\dataframe.py in _get_model(self, *args, **kwargs)
    123             model = KernelModelWrapper()
    124             arg_key = 'model_type'
--> 125             model.fit(self[[treatment] + confounders], self[outcome], variable_types=variable_types)
    126         else:
    127             model = RandomForestRegressor()

TypeError: can only concatenate list (not "dict_keys") to list

(awesome blog post btw!)

akelleh commented 6 years ago

Hi @nickvandewiele ! I've been refactoring that interface a bit leading up to the next release. You now have to pass z=['z1', 'z2'], z_types={'z1': 'c', 'z2': 'c'}. I know it's slightly redundant, but in order to allow arbitrary model types in the next release, we need an ordering on the z variables.