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

Not compatible with python 3.7 #5

Closed
vnnw opened this issue Aug 8, 2018 · 9 comments
Closed

Not compatible with python 3.7 #5

vnnw opened this issue Aug 8, 2018 · 9 comments

Comments

@vnnw
Copy link

vnnw commented Aug 8, 2018

Run the demo with Python 3.7 will raise a StopIteration exception, but works properly with Python 3.6.

In [1]: import dowhy
   ...: from dowhy.do_why import CausalModel
   ...: import dowhy.datasets
   ...:
   ...:

In [2]: data=dowhy.datasets.linear_dataset(
   ...:         beta=10,
   ...:         num_common_causes=5,
   ...:         num_instruments = 2,
   ...:         num_samples=10000,
   ...:         treatment_is_binary=True)
   ...:

In [3]: model=CausalModel(
   ...:         data = data["df"],
   ...:         treatment=data["treatment_name"],
   ...:         outcome=data["outcome_name"],
   ...:         graph=data["dot_graph"],
   ...:         )
   ...:
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
~/anaconda3/envs/dowhy/lib/python3.7/site-packages/pygraphviz/agraph.py in iteritems(self)
   1749             try:
-> 1750                 ah = gv.agnxtattr(self.handle, self.type, ah)
   1751                 yield (gv.agattrname(ah).decode(self.encoding),

StopIteration: agnxtattr

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
<ipython-input-3-e382d2368efa> in <module>()
      3         treatment=data["treatment_name"],
      4         outcome=data["outcome_name"],
----> 5         graph=data["dot_graph"],
      6         )
      7

~/Desktop/dowhy-master/dowhy/do_why.py in __init__(self, data, treatment, outcome, graph, common_causes, instruments, estimand_type, **kwargs)
     96                 self._outcome,
     97                 graph,
---> 98                 observed_node_names=self._data.columns.tolist()
     99             )
    100             self._common_causes = self._graph.get_common_causes(self._treatment, self._outcome)

~/Desktop/dowhy-master/dowhy/causal_graph.py in __init__(self, treatment_name, outcome_name, graph, common_cause_names, instrument_names, observed_node_names)
     26             self._graph = pgv.AGraph(graph, strict=True, directed=True)
     27
---> 28         self._graph = nx.drawing.nx_agraph.from_agraph(self._graph)
     29         self._graph = self.add_node_attributes(observed_node_names)
     30         self._graph = self.add_unobserved_common_cause(observed_node_names)

~/anaconda3/envs/dowhy/lib/python3.7/site-packages/networkx/drawing/nx_agraph.py in from_agraph(A, create_using)
     85
     86     # add graph attributes
---> 87     N.graph.update(A.graph_attr)
     88
     89     # add nodes, attributes to N.node_attr

~/anaconda3/envs/dowhy/lib/python3.7/site-packages/pygraphviz/agraph.py in keys(self)
   1738
   1739     def keys(self):
-> 1740         return list(self.__iter__())
   1741
   1742     def __iter__(self):

~/anaconda3/envs/dowhy/lib/python3.7/site-packages/pygraphviz/agraph.py in __iter__(self)
   1741
   1742     def __iter__(self):
-> 1743         for (k, v) in self.iteritems():
   1744             yield k
   1745
@amit-sharma
Copy link
Member

Thanks for pointing this out.
DoWhy depends on Pygraphviz for visualization and unfortunately there seems to be a problem in Pygraphviz for Python 3.7. I'm considering moving away from this dependency, allow me a few days to fix this.

@cpoptic
Copy link

cpoptic commented Aug 29, 2018

This issue applies also to Python 3.6.6 (on a Windows 10, 64 env). It appears to be a Pygraphviz installation issue.

@amit-sharma
Copy link
Member

I removed the dependency on pygraphviz, making it optional. If pygraphviz is not installed, the library falls back to matplotlib and plots causal graph using it. @vnnw @cpoptic can you check if it works for you?

@cpoptic
Copy link

cpoptic commented Sep 3, 2018

just did a git pull and pip install -U dowhy and I'm still getting the same result on Python 3.6

import dowhy works with no problems. But when I run from dowhy.do_why import Causal Model it get an error:

ModuleNotFoundError: No module named 'pygraphviz'

So it appears the dowhy package imports fine, but the do_why module is still dependent on pygraphviz.

@amit-sharma
Copy link
Member

Thanks @cpoptic Not sure why it still shows an error. I did check with python 3.6 in a virtualenv and it worked.

Maybe an earlier install of dowhy is still being called? To make sure, can you try the following code which relies on the source distribution only (and does not use pip)?

[Run this code from the root directory of dowhy]
`import os, sys
sys.path.append(os.path.abspath("./"))
import numpy as np
import pandas as pd

import dowhy
from dowhy.do_why import CausalModel`

@impredicative
Copy link

Any formal update? Is 3.7 fully supported now?

@amit-sharma
Copy link
Member

amit-sharma commented Feb 12, 2019

@impredicative Yes, it should work in 3.7. Let me know if you face any problems.

@akelleh
Copy link
Contributor

akelleh commented Feb 26, 2019

@amit-sharma two weeks with no problem reported -- safe to close?

@amit-sharma
Copy link
Member

yes, closing it now. @impredicative if you face any problems with 3.7, let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants