Repository navigation
MAINT: used add_edges_from instead of initialising nx.Graph() with edges in cycles.py - #7402
Schefflera-Arboricola wants to merge 5 commits into
Conversation
add_edges_from instead of initialising nx.Graph() with edges in cycles.py
rossbar
left a comment
There was a problem hiding this comment.
IMO it's worth taking a look at to_networkx_graph itself to see if that can't be made not to warn. The Graph(<edgelist>) pattern is extremely common, and converting all of those to use .add_edges_from explicitly is likely a lot of churn!
I initially did think of modifying Another thought was to remove all the warnings and just have a Thanks! |
|
Is there a reason why the import is done on every call to Maybe there are better ways to check if the graph data is a numpy/pandas/scipy object without having to try importing the module. |
Yes, I don't think the entire conditional can be moved as-is, however it might be worth trying adding an additional condition before the attempted imports specifically for edge lists.
Yes, this is intentional - numpy, scipy, and pandas are soft dependencies and everything is lazy-loaded, so only functions that actually use these libraries attempt to import them. |
|
FWIW this definitely extends beyond just
This gives ~500 errors/failures, most of which are related to the So - there are a couple options here; replacing the warnings with |
|
Has anyone tried just removing the import and the The type-based dispatching here didn't used to be the mechanism used. And if we don't use it we do get rid of the import being tried upon each construction. BUT is that really the problem here? The reason for using e.g So, I will ask a perhaps silly question @albertferras-vrf : Is the problem that the failed imports take too long, or that the warnings pollute the log? To stop the pollution of the logs, can we set a warnings filter so they don't go into the log? And, there is, of course, a way to write the code so the import is tried at the module level with different versions of the function being defined based on what can be imported. But I suspect that makes the code pretty ugly. So, let's identify the problem first. Is it the speed or the logging pollution that is the issue here? Or are there two issues? :) |
The main reason I created the issue #7401 was due to all the warnings that appeared in the logs. |
fixes #7401
I've fixed instances in
cycles.pybut there probably would be other such instances of initialisations of Graph with edges