Skip to content

Commit

Permalink
Release 0.12.0 (#248)
Browse files Browse the repository at this point in the history
* 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 <kyle_lim@mckinsey.com>

* 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 <34248114+qbphilip@users.noreply.github.com>

---------

Co-authored-by: GabrielAz <gabriel.azevedoferreira@quantumblack.com>
Co-authored-by: Gabriel Azevedo Ferreira <57528979+GabrielAzevedoFerreiraQB@users.noreply.github.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

* unlocking numpy (mckinsey#238)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release 0.11.2 (mckinsey#239)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* 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 <kyle_lim@mckinsey.com>

* 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 <34248114+qbphilip@users.noreply.github.com>

---------

Co-authored-by: GabrielAz <gabriel.azevedoferreira@quantumblack.com>
Co-authored-by: Gabriel Azevedo Ferreira <57528979+GabrielAzevedoFerreiraQB@users.noreply.github.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

* unlocking numpy (mckinsey#238)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release 0.11.2 (mckinsey#239)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* adding cython to config

* adding cython to config

* adding cython to config

* adding cython to config

---------

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>
Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

* 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 <oentaryorj@users.noreply.github.com>

* Update tests/test_plotting.py

Co-authored-by: Richard Oentaryo <oentaryorj@users.noreply.github.com>

* 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 <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: GabrielAz <gabriel.azevedoferreira@quantumblack.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>
Co-authored-by: Gabriel Azevedo Ferreira <57528979+GabrielAzevedoFerreiraQB@users.noreply.github.com>
Co-authored-by: Richard Oentaryo <oentaryorj@users.noreply.github.com>

* 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 <snyk-bot@snyk.io>

* 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 <kyle_lim@mckinsey.com>

* 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 <34248114+qbphilip@users.noreply.github.com>

---------

Co-authored-by: GabrielAz <gabriel.azevedoferreira@quantumblack.com>
Co-authored-by: Gabriel Azevedo Ferreira <57528979+GabrielAzevedoFerreiraQB@users.noreply.github.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>

* unlocking numpy (mckinsey#238)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release 0.11.2 (mckinsey#239)

Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

* Release Notes

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>

---------

Co-authored-by: ElisabethSesterHussQB <92664441+ElisabethSesterHussQB@users.noreply.github.com>
Co-authored-by: kyle_lim <kyle_lim@mckinsey.com>
Co-authored-by: Philip Pilgerstorfer <34248114+qbphilip@users.noreply.github.com>
Co-authored-by: Gabriel Azevedo <gabriel_azevedo_ferreira@mckinsey.com>
Co-authored-by: Serene Yeo <118331898+SereneYeo@users.noreply.github.com>
Co-authored-by: Richard Oentaryo <oentaryorj@users.noreply.github.com>
Co-authored-by: Leon Nallamuthu <38660312+leonnallamuthu@users.noreply.github.com>
Co-authored-by: snyk-bot <snyk-bot@snyk.io>
  • Loading branch information
9 people authored Apr 20, 2023
1 parent 843b54a commit b84e7cf
Show file tree
Hide file tree
Showing 46 changed files with 13,108 additions and 1,621 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ utils:
conda create --name=causalnex_env python=${PYTHON_VERSION} -y
conda activate causalnex_env
conda install -y virtualenv
pip install cython
pip install -U pip setuptools wheel
sudo apt-get install graphviz
Expand Down Expand Up @@ -182,6 +183,7 @@ jobs:
name: Success!
command: echo "All checks passed"


###############################################################################
workflows:
version: 2
Expand Down
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,7 @@ CausalNex is a Python package. To install it, simply run:
pip install causalnex
```

Since pygraphviz can be difficult to install, esp. on Windows machines, the requirement is optional.
If you want to use the causalnex native plotting tools, you can use
```bash
pip install "causalnex[plot]"
```
Alternatively, you can use the `networkx` drawing functionality for visualisations with fewer dependencies.

Use `all` for a full installation of dependencies (only the plotting right now):
Use `all` for a full installation of dependencies:
```bash
pip install "causalnex[all]"
```
Expand Down
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Upcoming release
# Release 0.12.0
* Switch to Pyvis for graph visualisation and remove dependency on Graphviz

# Release 0.11.2
* Support newer version of Numpy
* Support newer version of Scikit-learn
* Remove python 3.6, 3.7 support
Expand Down
2 changes: 1 addition & 1 deletion causalnex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
causalnex toolkit for causal reasoning (Bayesian Networks / Inference)
"""

__version__ = "0.11.2"
__version__ = "0.12.0"

__all__ = ["structure", "discretiser", "evaluation", "inference", "network", "plots"]
13 changes: 2 additions & 11 deletions causalnex/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,13 @@
"""
``causalnex.plots`` provides functionality to visualise structure models.
"""

__all__ = [
"plot_structure",
"NODE_STYLE",
"EDGE_STYLE",
"GRAPH_STYLE",
"color_gradient_string",
"display_plot_ipython",
"display_plot_mpl",
]

from .display import display_plot_ipython, display_plot_mpl
from .plots import (
EDGE_STYLE,
GRAPH_STYLE,
NODE_STYLE,
color_gradient_string,
plot_structure,
)
from .display import display_plot_ipython
from .plots import EDGE_STYLE, GRAPH_STYLE, NODE_STYLE, plot_structure
121 changes: 39 additions & 82 deletions causalnex/plots/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,97 +25,54 @@
#
# See the License for the specific language governing permissions and
# limitations under the License.
"""Methods to display styled pygraphgiz plots."""
"""Methods to display styled pyvis plots."""
import json
from html import escape
from typing import Dict

import io
from typing import Any, Tuple
from IPython.lib.display import IFrame
from pyvis.network import Network

try:
from pygraphviz.agraph import AGraph
except ImportError:
AGraph = Any

try:
from IPython.display import Image
except ImportError:
Image = Any

try:
import matplotlib.pyplot as plt
from matplotlib.axes import Axes
from matplotlib.figure import Figure
except ImportError:
Axes = Any
Figure = Any


def display_plot_ipython(viz: AGraph, prog: str = "neato") -> Image:
def display_plot_ipython(
viz: Network,
output_filename: str,
layout_kwargs: Dict[str, Dict] = None,
) -> IFrame:
"""
Displays a pygraphviz object using ipython.
Displays a PyVis object using ipython.
Args:
viz: pygraphviz object to render.
prog: The graph layout. Avaliable are:
dot, neato, fdp, sfdp, twopi and circo
viz: pyvis object to render.
output_filename: write html to a given path, e.g. "./plot.html". File as to end in ".html"
layout_kwargs: Dictionary to set the `layout` and `physics` of the graph.
Example:
::
>>> layout_kwargs = {
"physics": {
"solver": "repulsion"
},
"layout": {
"hierarchical": {
"enabled": True
}
}
}
Returns:
IPython Image object. Renders in a notebook.
IPython IFrame object. Renders in a notebook.
Raises:
ImportError: if IPython is not installed (optional dependency).
"""
layout_kwargs = layout_kwargs or {}
viz.set_options(options=json.dumps(layout_kwargs))

if Image is Any:
raise ImportError("display_plot_ipython method requires IPython installed.")

return Image(viz.draw(format="png", prog=prog))


def display_plot_mpl(
viz: AGraph,
prog: str = "neato",
ax: Axes = None,
pixel_size_in: float = 0.01,
) -> Tuple[Figure, Axes]:
"""
Displays a pygraphviz object using matplotlib.
Args:
viz: pygraphviz object to render.
prog: The graph layout. Avaliable are:
dot, neato, fdp, sfdp, twopi and circo
ax: Optional matplotlib axes to plot on.
pixel_size_in: Scaling multiple for the plot.
Returns:
IPython Image object. Renders in a notebook.
Raises:
ImportError: if matplotlib is not installed (optional dependency).
"""

if Figure is Any:
raise ImportError("display_plot_mpl method requires matplotlib installed.")

# bytes:
s = viz.draw(format="png", prog=prog)
# convert to numpy array
array = plt.imread(io.BytesIO(s))
x_dim, y_dim, _ = array.shape
html = viz.generate_html()

# handle passed axis
if ax is not None:
ax.imshow(array)
ax.axis("off")
return None, ax
with open(output_filename, mode="w", encoding="UTF-8") as f:
f.write(html)

# handle new axis
f, ax = plt.subplots(1, 1, figsize=(y_dim * pixel_size_in, x_dim * pixel_size_in))
ax.imshow(array)
ax.axis("off")
f.tight_layout(pad=0.0)
return f, ax
return IFrame(
src=output_filename,
width=viz.width,
height=viz.height,
extras=[f"srcdoc='{escape(viz.generate_html(notebook=False))}'"],
)
Loading

0 comments on commit b84e7cf

Please sign in to comment.