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
Construct graph from a few more input data structures (mimicking networkx) #434
Conversation
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.
Great! Looks good to me, I have a small suggestion for using an internal type that slightly simplifies the code, and I'm not sure if we should make the name attribute a choice, but perhaps @ntamas has some comments about it.
We could take a look at all other input functions that networkx
supports, it would be nice to also support the other options.
Ok, I moved a bunch of constructor functions into a separate module called I think we are now covering all the input options they cover. Docs on arguments for some of the new constructors are still poor, happy to improve in the next few commits. |
Since I was there I also moved a bunch of constructors (almost all, in fact) into the new module, which reduces the size of Ideally we would actually have separate modules for say constructing from file versus from live objects, but that seems a little much for this humble PR, so let's plan that for after this one is merged unless you guys have any urgency, in which case we can do it here as well (I can, or you can push here @ntamas). |
Yay, that's definitely an improvement, thanks! Ideally, in the long term (i.e. the duration of the CZI grant) we should be moving towards having many small modules grouped around topics instead of a single monolithic Maybe now that we also have the |
Love that idea! I suggest a two step process:
|
Yes, I think this is doable; I think if you implement a method like
then you can link it to the Graph class with Still, there are too many parallel things going on in the |
Don't worry, I'll just chug along against develop now that we have it, and this PR can come after those are done |
Haven't reviewed the whole PR yet but I've added some comments that are worth considering. One general problem I have with the new def construct_graph_somehow(first_arg, second_arg, *, graph_factory=Graph):
... and then simulate the "old" class methods of the Graph class with another decorator: from functools import wraps
def igraph_classmethod(func):
@wraps(func)
def wrapped(cls, *args, **kwds):
kwds["graph_factory"] = cls
return func(*args, **kwds)
return wrapped The problem with this proposal is that we will very likely introduce circular imports by having |
Also, when reviewing the PR, I will simply assume that you did not modify the bodies of the functions that you moved out from the |
Thanks @ntamas
I checked if |
Fair enough, you have a point here; in this case, let's mark these methods with a leading underscore so it is clear that they are internal. I'm afraid that PyDoctor would pick them up and include them in the documentation if we don't do so, and maybe people coming from NetworkX would feel a temptation to import these functions directly instead of relying on the class methods. |
I should add export functions for dict of dicts and friends |
Ok now we have export functions for each import function in IO, which should cover everything networkx does and then some. This PR is somewhat sensitive since it generates a decent amonut of new API estate, so it'd be great if @vtraag you could have a look If you guys think it's ok I can add proper docs and then we can merge. |
I included PR #408 in this one since they would conflict and it's a closely related task. Closing the other one. |
Extended tests a little including some trivial cases, added docs and docstrings, and some flexibility as of the "name" attribute, should be ready for merge |
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.
Great to see all these input/output structure being supported, that makes it a lot easier to work with various existing data structures. Nice job!
Also very good to see so many functions from __init__.py
being separated out into smaller files, that makes it a lot easier to navigate. I did not review the adjacency, file, images and libraries related stuff, assuming that's still the same as before, but just moved.
I only have some smaller comments for a couple of things. One question is perhaps worth discussing more generally: the name of SequenceDict
instead of ListDict
. It seems to be a bit inconsistent with the DictList
, which can in principle also be a sequence. Not sure what your considerations were here? Also curious to hear what others think.
src/igraph/io/objects.py
Outdated
result is likely to be fit as long as it's iterable and yields | ||
dict-like objects with every iteration. | ||
|
||
@param vertices: the data source for the vertices or C{None} if |
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 "data source" should this be? This can simply be any iterable that provides names for vertices? Perhaps then we should make explicit that it's an iterable?
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.
From later description, it seems as if this is a list of dicts as well?
Thanks Vincent, I've implemented most suggestions except API breaking changes. For those, I'd say if @ntamas is fine merging this PR then I can make separate ones breaking the API, to keep things tidy. |
Thanks @iosonofabio ! Can you also update the |
Aiming to fix #433 and related forum request, and matching (roughly) networkx's range of input fuctions:
Graph.ListDict
Graph.DictDict
(we already had:
Graph.TupleList
Graph.DictList
)
Notes:
Graph.ListDict
currently takes no edge attributes,Graph.DictDict
is better for that purpose@szhorvat @ntamas do you feel this addresses the issue? If so I'd be happy to improve docs.
TODO:
"name"
attribute: fixed or not (API break)?