Skip to content

Commit b84e7cf

Browse files
GabrielAzevedoFerreiraQBElisabethSesterHussQBkylelim-mckinseyqbphilipGabriel Azevedo
authored
Release 0.12.0 (#248)
* Limiting numpy version (mckinsey#217) * adding line on yml - no effect * adding line on yml - no effect * changing req.txt * changing req.txt * changing req.txt * adding setuptools requirement (mckinsey#218) * adding setuptools requirement * adding setuptools requirement * update dictionaries to pass linting (mckinsey#230) * Refactor/unlock numpy kl (mckinsey#235) * unlocking numpy * unlocking numpy * unlocking numpy * dependency fixes for docs and linters * requirement fixes : numpy <1.24 for all python versions --------- Co-authored-by: kyle_lim <[email protected]> * Simplifying requirements - Numpy version range (mckinsey#236) * Remove python 3.6 and 3.7 support (mckinsey#234) * remove python 3.6 and 3.7 support * update documentation * remove comment regarding ignoring a warning when running `make build-docs` * removing ipython from test requiremnets * Update README.md Co-authored-by: Philip Pilgerstorfer <[email protected]> --------- Co-authored-by: GabrielAz <[email protected]> Co-authored-by: Gabriel Azevedo Ferreira <[email protected]> Co-authored-by: Philip Pilgerstorfer <[email protected]> * unlocking numpy (mckinsey#238) Co-authored-by: Gabriel Azevedo <[email protected]> * Release 0.11.2 (mckinsey#239) Co-authored-by: Gabriel Azevedo <[email protected]> * Replacing Pygraphviz with Pyvis (mckinsey#237) * Replacing Pygraphviz with Pyvis * Replacing Pygraphviz with Pyvis * Replacing Pygraphviz with Pyvis * temp (#242) * Limiting numpy version (mckinsey#217) * adding line on yml - no effect * adding line on yml - no effect * changing req.txt * changing req.txt * changing req.txt * adding setuptools requirement (mckinsey#218) * adding setuptools requirement * adding setuptools requirement * update dictionaries to pass linting (mckinsey#230) * Refactor/unlock numpy kl (mckinsey#235) * unlocking numpy * unlocking numpy * unlocking numpy * dependency fixes for docs and linters * requirement fixes : numpy <1.24 for all python versions --------- Co-authored-by: kyle_lim <[email protected]> * Simplifying requirements - Numpy version range (mckinsey#236) * Remove python 3.6 and 3.7 support (mckinsey#234) * remove python 3.6 and 3.7 support * update documentation * remove comment regarding ignoring a warning when running `make build-docs` * removing ipython from test requiremnets * Update README.md Co-authored-by: Philip Pilgerstorfer <[email protected]> --------- Co-authored-by: GabrielAz <[email protected]> Co-authored-by: Gabriel Azevedo Ferreira <[email protected]> Co-authored-by: Philip Pilgerstorfer <[email protected]> * unlocking numpy (mckinsey#238) Co-authored-by: Gabriel Azevedo <[email protected]> * Release 0.11.2 (mckinsey#239) Co-authored-by: Gabriel Azevedo <[email protected]> --------- Co-authored-by: ElisabethSesterHussQB <[email protected]> Co-authored-by: kyle_lim <[email protected]> Co-authored-by: Philip Pilgerstorfer <[email protected]> Co-authored-by: Gabriel Azevedo <[email protected]> * adding cython to config * adding cython to config * adding cython to config * adding cython to config --------- Co-authored-by: Gabriel Azevedo <[email protected]> Co-authored-by: ElisabethSesterHussQB <[email protected]> Co-authored-by: kyle_lim <[email protected]> Co-authored-by: Philip Pilgerstorfer <[email protected]> * Replace pygraphviz plotting with pyvis (mckinsey#228) * initial draft for pyvis plotting * modify edge length and mass for strong style and return pyvis object * add pytests and fix sklearn plotting function * update to include pyvis in requirements * add in notebook check tests for test_plot_dag * downgrade pyvis for compatibility * update to latest plotting functions * update requirements to exclude pygraphviz * upgrading ipython * moving ipython as main requirement * simplify plot_structure function * remove unused code and add test cases when needed * reset pyvis version to see if .show() is working on v0.3.1 * set ipython and python versions * undo previous change (ipython version change) * remove ipython version from requirements * re-add ipython version to requirements * change ipython+python version * undo change ipython+python version * check for different ipython versions * add quotation marks in requirements.txt * revert back to ipython>=8.10.0 * try out ipython requirements from kedro * revert back to ipython>=8.10 * change ipython requirements to successfully create environments * Updated pyvis tutorials (mckinsey#232) * update tutorials and adjust default values to improve output * allow user to change layout in plot_dag function before calling .show() * display df without dataframe_image * fix dataframe_image No such file or directory * remove one cell beacause unused * incorporate windows solution from Kyle * fix typo * change plot_structure documentation * change plot_dag documentation * check and correct all notebooks * remove python 3.6 and 3.7 support * update documentation * remove comment regarding ignoring a warning when running `make build-docs` * removing ipython from test requiremnets * refactoring plot syntax and changing logic in plot_dag * addressing Gabriel's comments * removing unused IPython conditional import * refactoring code to use display * Docs - update 01-tutorial * updating first tutotiral * updating plotting tutorial * updating plotting tutorial * updating display api * fixing bug - displau * fixing notebooks * fixing notebooks * fixing notebooks * fixing notebooks * Replacing Pygraphviz with Pyvis * Replacing Pygraphviz with Pyvis * Replacing Pygraphviz with Pyvis * updating pyvis version * updating notebook * Richard Comments - batch 1 * Update tests/test_plotting.py Co-authored-by: Richard Oentaryo <[email protected]> * Update tests/test_plotting.py Co-authored-by: Richard Oentaryo <[email protected]> * Richard Comments - batch 2 * adjust node color test to include background color * docs * docs * test * fixing mdlp with cython * fixing mdlp with cython * test * removing cython from requirements * adding cython to config --------- Co-authored-by: ElisabethSesterHussQB <[email protected]> Co-authored-by: GabrielAz <[email protected]> Co-authored-by: Gabriel Azevedo <[email protected]> Co-authored-by: Gabriel Azevedo Ferreira <[email protected]> Co-authored-by: Richard Oentaryo <[email protected]> * fix: requirements.txt to reduce vulnerabilities (#247) The following vulnerabilities are fixed by pinning transitive dependencies: - https://snyk.io/vuln/SNYK-PYTHON-IPYTHON-3318382 Co-authored-by: snyk-bot <[email protected]> * test * Release Notes 0.12.0 (#249) * temp (#242) * Limiting numpy version (mckinsey#217) * adding line on yml - no effect * adding line on yml - no effect * changing req.txt * changing req.txt * changing req.txt * adding setuptools requirement (mckinsey#218) * adding setuptools requirement * adding setuptools requirement * update dictionaries to pass linting (mckinsey#230) * Refactor/unlock numpy kl (mckinsey#235) * unlocking numpy * unlocking numpy * unlocking numpy * dependency fixes for docs and linters * requirement fixes : numpy <1.24 for all python versions --------- Co-authored-by: kyle_lim <[email protected]> * Simplifying requirements - Numpy version range (mckinsey#236) * Remove python 3.6 and 3.7 support (mckinsey#234) * remove python 3.6 and 3.7 support * update documentation * remove comment regarding ignoring a warning when running `make build-docs` * removing ipython from test requiremnets * Update README.md Co-authored-by: Philip Pilgerstorfer <[email protected]> --------- Co-authored-by: GabrielAz <[email protected]> Co-authored-by: Gabriel Azevedo Ferreira <[email protected]> Co-authored-by: Philip Pilgerstorfer <[email protected]> * unlocking numpy (mckinsey#238) Co-authored-by: Gabriel Azevedo <[email protected]> * Release 0.11.2 (mckinsey#239) Co-authored-by: Gabriel Azevedo <[email protected]> --------- Co-authored-by: ElisabethSesterHussQB <[email protected]> Co-authored-by: kyle_lim <[email protected]> Co-authored-by: Philip Pilgerstorfer <[email protected]> Co-authored-by: Gabriel Azevedo <[email protected]> * Release Notes --------- Co-authored-by: ElisabethSesterHussQB <[email protected]> Co-authored-by: kyle_lim <[email protected]> Co-authored-by: Philip Pilgerstorfer <[email protected]> Co-authored-by: Gabriel Azevedo <[email protected]> --------- Co-authored-by: ElisabethSesterHussQB <[email protected]> Co-authored-by: kyle_lim <[email protected]> Co-authored-by: Philip Pilgerstorfer <[email protected]> Co-authored-by: Gabriel Azevedo <[email protected]> Co-authored-by: Serene Yeo <[email protected]> Co-authored-by: Richard Oentaryo <[email protected]> Co-authored-by: Leon Nallamuthu <[email protected]> Co-authored-by: snyk-bot <[email protected]>
1 parent 843b54a commit b84e7cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+13108
-1621
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ utils:
2424
conda create --name=causalnex_env python=${PYTHON_VERSION} -y
2525
conda activate causalnex_env
2626
conda install -y virtualenv
27+
pip install cython
2728
pip install -U pip setuptools wheel
2829
sudo apt-get install graphviz
2930
@@ -182,6 +183,7 @@ jobs:
182183
name: Success!
183184
command: echo "All checks passed"
184185

186+
185187
###############################################################################
186188
workflows:
187189
version: 2

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,7 @@ CausalNex is a Python package. To install it, simply run:
5252
pip install causalnex
5353
```
5454

55-
Since pygraphviz can be difficult to install, esp. on Windows machines, the requirement is optional.
56-
If you want to use the causalnex native plotting tools, you can use
57-
```bash
58-
pip install "causalnex[plot]"
59-
```
60-
Alternatively, you can use the `networkx` drawing functionality for visualisations with fewer dependencies.
61-
62-
Use `all` for a full installation of dependencies (only the plotting right now):
55+
Use `all` for a full installation of dependencies:
6356
```bash
6457
pip install "causalnex[all]"
6558
```

RELEASE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Upcoming release
2+
# Release 0.12.0
3+
* Switch to Pyvis for graph visualisation and remove dependency on Graphviz
4+
5+
# Release 0.11.2
26
* Support newer version of Numpy
37
* Support newer version of Scikit-learn
48
* Remove python 3.6, 3.7 support

causalnex/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
causalnex toolkit for causal reasoning (Bayesian Networks / Inference)
3131
"""
3232

33-
__version__ = "0.11.2"
33+
__version__ = "0.12.0"
3434

3535
__all__ = ["structure", "discretiser", "evaluation", "inference", "network", "plots"]

causalnex/plots/__init__.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,13 @@
2929
"""
3030
``causalnex.plots`` provides functionality to visualise structure models.
3131
"""
32-
3332
__all__ = [
3433
"plot_structure",
3534
"NODE_STYLE",
3635
"EDGE_STYLE",
3736
"GRAPH_STYLE",
38-
"color_gradient_string",
3937
"display_plot_ipython",
40-
"display_plot_mpl",
4138
]
4239

43-
from .display import display_plot_ipython, display_plot_mpl
44-
from .plots import (
45-
EDGE_STYLE,
46-
GRAPH_STYLE,
47-
NODE_STYLE,
48-
color_gradient_string,
49-
plot_structure,
50-
)
40+
from .display import display_plot_ipython
41+
from .plots import EDGE_STYLE, GRAPH_STYLE, NODE_STYLE, plot_structure

causalnex/plots/display.py

Lines changed: 39 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -25,97 +25,54 @@
2525
#
2626
# See the License for the specific language governing permissions and
2727
# limitations under the License.
28-
"""Methods to display styled pygraphgiz plots."""
28+
"""Methods to display styled pyvis plots."""
29+
import json
30+
from html import escape
31+
from typing import Dict
2932

30-
import io
31-
from typing import Any, Tuple
33+
from IPython.lib.display import IFrame
34+
from pyvis.network import Network
3235

33-
try:
34-
from pygraphviz.agraph import AGraph
35-
except ImportError:
36-
AGraph = Any
3736

38-
try:
39-
from IPython.display import Image
40-
except ImportError:
41-
Image = Any
42-
43-
try:
44-
import matplotlib.pyplot as plt
45-
from matplotlib.axes import Axes
46-
from matplotlib.figure import Figure
47-
except ImportError:
48-
Axes = Any
49-
Figure = Any
50-
51-
52-
def display_plot_ipython(viz: AGraph, prog: str = "neato") -> Image:
37+
def display_plot_ipython(
38+
viz: Network,
39+
output_filename: str,
40+
layout_kwargs: Dict[str, Dict] = None,
41+
) -> IFrame:
5342
"""
54-
Displays a pygraphviz object using ipython.
55-
43+
Displays a PyVis object using ipython.
5644
Args:
57-
viz: pygraphviz object to render.
58-
59-
prog: The graph layout. Avaliable are:
60-
dot, neato, fdp, sfdp, twopi and circo
61-
45+
viz: pyvis object to render.
46+
output_filename: write html to a given path, e.g. "./plot.html". File as to end in ".html"
47+
layout_kwargs: Dictionary to set the `layout` and `physics` of the graph.
48+
Example:
49+
::
50+
>>> layout_kwargs = {
51+
"physics": {
52+
"solver": "repulsion"
53+
},
54+
"layout": {
55+
"hierarchical": {
56+
"enabled": True
57+
}
58+
}
59+
}
6260
Returns:
63-
IPython Image object. Renders in a notebook.
64-
61+
IPython IFrame object. Renders in a notebook.
6562
Raises:
6663
ImportError: if IPython is not installed (optional dependency).
6764
"""
65+
layout_kwargs = layout_kwargs or {}
66+
viz.set_options(options=json.dumps(layout_kwargs))
6867

69-
if Image is Any:
70-
raise ImportError("display_plot_ipython method requires IPython installed.")
71-
72-
return Image(viz.draw(format="png", prog=prog))
73-
74-
75-
def display_plot_mpl(
76-
viz: AGraph,
77-
prog: str = "neato",
78-
ax: Axes = None,
79-
pixel_size_in: float = 0.01,
80-
) -> Tuple[Figure, Axes]:
81-
"""
82-
Displays a pygraphviz object using matplotlib.
83-
84-
Args:
85-
viz: pygraphviz object to render.
86-
87-
prog: The graph layout. Avaliable are:
88-
dot, neato, fdp, sfdp, twopi and circo
89-
90-
ax: Optional matplotlib axes to plot on.
91-
92-
pixel_size_in: Scaling multiple for the plot.
93-
94-
Returns:
95-
IPython Image object. Renders in a notebook.
96-
97-
Raises:
98-
ImportError: if matplotlib is not installed (optional dependency).
99-
"""
100-
101-
if Figure is Any:
102-
raise ImportError("display_plot_mpl method requires matplotlib installed.")
103-
104-
# bytes:
105-
s = viz.draw(format="png", prog=prog)
106-
# convert to numpy array
107-
array = plt.imread(io.BytesIO(s))
108-
x_dim, y_dim, _ = array.shape
68+
html = viz.generate_html()
10969

110-
# handle passed axis
111-
if ax is not None:
112-
ax.imshow(array)
113-
ax.axis("off")
114-
return None, ax
70+
with open(output_filename, mode="w", encoding="UTF-8") as f:
71+
f.write(html)
11572

116-
# handle new axis
117-
f, ax = plt.subplots(1, 1, figsize=(y_dim * pixel_size_in, x_dim * pixel_size_in))
118-
ax.imshow(array)
119-
ax.axis("off")
120-
f.tight_layout(pad=0.0)
121-
return f, ax
73+
return IFrame(
74+
src=output_filename,
75+
width=viz.width,
76+
height=viz.height,
77+
extras=[f"srcdoc='{escape(viz.generate_html(notebook=False))}'"],
78+
)

0 commit comments

Comments
 (0)