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
add constructor to main widget #258
Conversation
Hi @vaniisgh thanks for taking this on! This looks like a good start but there are a few things to clean up. TODO:
Also looking at the test failures there are unfortunately several due to neo4j which aren't your fault. This makes it trickier to see if your are causing issues but you can look more closely by clicking on the |
directed : bool | ||
If True all edges will be given 'directed' as a class if | ||
they do not already have it. | ||
""" | ||
if path.isfile(str(json_file)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this fully protect us if the user passes in a dict
?
ipycytoscape/cytoscape.py
Outdated
|
||
from spectate import mvc | ||
from traitlets import TraitType, TraitError | ||
|
||
from pandas import DataFrame |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently don't require pandas
so this need to either be an optional import or the check below needs to check for pandas
in the graph.__class__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a change to fix this, but I am not sure I passed the kwargs correctly to the add_graph_from_df correctly ... cold you please let me know what the correct way to do that would be? :)
hey thank you so much for the feedback! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good! I'll try look more closely (e.g. at the pandas import) in the coming days. For now I left a quick comment on the docstring and approved the github actions.
ipycytoscape/cytoscape.py
Outdated
- graph: | ||
type: string|dict|pandas.DataFrame|networkx.Graph|neo4j|Graph|None | ||
description: graph passes is checked to be of one of the declared | ||
types, and the corresponding object is added to the | ||
graph attribute of the DOM object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this! Can you update this to be in the numpydoc style as described here: https://numpydoc.readthedocs.io/en/latest/format.html#parameters
You can see an example here:
ipycytoscape/ipycytoscape/cytoscape.py
Lines 450 to 458 in b80a913
Parameters | |
---------- | |
g : networkx graph | |
receives a generic NetworkX graph. more info in | |
https://networkx.github.io/documentation/ | |
directed : bool | |
If true all edges will be given directed as class if | |
they do not already have it. Equivalent to adding | |
'directed' to the 'classes' attribute of edge.data for all edges |
ipycytoscape/cytoscape.py
Outdated
if isinstance(graph, nx.Graph): | ||
self.graph.add_graph_from_networkx(graph) | ||
elif isinstance(graph, (dict, str)): | ||
self.graph.add_graph_from_json(graph) | ||
elif graph.__class__.__name__ == "DataFrame": | ||
self.graph.add_graph_from_df(graph, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is the approach I've always taken to optional imports in the past, but looking at it now and reading around on the internet a bit I think this is probably not the best way. This is brittle to changes in class names and also to other objects that have a similar classname. I think a better approach would be to try to import pandas
at the top level like this:
try:
import pandas as pd
except ImportError:
pd = None
and then for this checks do:
elif pd and isinstance(graph, pd.DataFrame)
what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems like a good solution really. :) Though then should we do something similar for the neo4j graphs (because Graph is a far more common class name than DataFrame)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup that's the best way forward!
ipycytoscape/cytoscape.py
Outdated
else: | ||
if isinstance(graph, Graph): | ||
self.graph = graph |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason not to make these elif
s at the same level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I was thinking was, that the graph.class.name is "Graph" for both objects, and I didn't want to add the optional import, I will recheck though.
I think it should be better now :) |
Thanks for the ping! This slipped through the cracks for me - can look later |
ipycytoscape/cytoscape.py
Outdated
Checked to be of one of the declared types, and graph object | ||
corresponding to it is added as a Graph attribute to the | ||
CytoscapeWidget DOM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked to be of one of the declared types, and graph object | |
corresponding to it is added as a Graph attribute to the | |
CytoscapeWidget DOM. | |
The graph to initialize with. Equivalent to calling the appropriate ``CytoscapeWidget.graph.add_graph_from_` method. |
Is this clearer? We maybe should stay away from using words like DOM
as I suspect that isn't a super clear term to most python users.
@ianhi should i close this ? |
Thank you @vaniisgh !! This is a great addition and we can always iterate more as needed. |
Definitely not that - I'm really sorry about the long periods of non-responsiveness that's totally on me. I really appreciate you coming and putting the effort to make a positive change. I can't promise to be perfect, but I can promise that I will at least try to be more honest myself about what I can claim to do. Also don't be scared to ping more and more often (though ideally course you shouldn't have to :/ ) |
This should be live in version |
Hey,
This issue ( #94 ) looked interesting and beginner-friendly,
I just wanted to know if this was a good start.