[BUG] Using layout_umap and getting key error
See original GitHub issueExpected Behavior
a graph layout using UMAP for dim reduction to 2d
Actual Behavior
coming from layouts\auto.py KeyError: ‘2’
Example Code
Please see How to create a Minimal, Reproducible example for some guidance on creating the best possible example of the problem
import networkx as nx
from graspologic.layouts import layout_umap
g = nx.erdos_renyi_graph(10, 0.7, directed=False)
layout_umap(g)
Full Traceback
Paste the full traceback in case there is an exception
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-17-1c062a6ca19a> in <module>
3
4 g = nx.erdos_renyi_graph(10, 0.7, directed=False)
----> 5 layout_umap(g)
~\miniconda3\lib\site-packages\graspologic\layouts\auto.py in layout_umap(graph, min_dist, n_neighbors, max_edges, random_seed)
177 min_dist=min_dist, n_neighbors=n_neighbors, random_state=random_seed
178 ).fit_transform(tensors)
--> 179 positions = _node_positions_from(lcc_graph, labels, points, random_seed=random_seed)
180 return lcc_graph, positions
181
~\miniconda3\lib\site-packages\graspologic\layouts\auto.py in _node_positions_from(graph, labels, down_projection_2d, random_seed)
241 scaled_points = _scale_points(down_projection_2d, covered_area)
242 partitions = leiden(graph, random_seed=random_seed)
--> 243 positions = [
244 NodePosition(
245 node_id=key,
~\miniconda3\lib\site-packages\graspologic\layouts\auto.py in <listcomp>(.0)
246 x=scaled_points[index][0],
247 y=scaled_points[index][1],
--> 248 size=sizes[key],
249 community=partitions[key],
250 )
KeyError: '2'
Your Environment
- Python version: 3.8
- graspologic version:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Python KeyError Exceptions and How to Handle Them
In this tutorial, you'll learn how to handle Python KeyError exceptions. They are often caused by a bad key lookup in a dictionary,...
Read more >I'm getting Key error in python - Stack Overflow
A KeyError generally means the key doesn't exist. So, are you sure the path key exists? From the official python docs: exception KeyError....
Read more >How to Fix KeyError Exceptions in Python - Rollbar
The Python KeyError is an exception that occurs when an attempt is made to access an item in a dictionary that does not...
Read more >How to fix Python KeyError Exceptions in simple steps?
There are a number of ways of handling a KeyError exception. Using get(). The get()is useful in cases where the exception is raised...
Read more >keyerror in Python – How to Fix Dictionary Error
When working with dictionaries in Python, a KeyError gets raised when you try to access an item that doesn't exist in a Python...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

totally fine with removing it from utils, personally!
@bdpedigo blech - we generate the edge list that leiden requires in
utils.pywhere we generate aList[Tuple[str, str, float]]. That’s reasonable as a utility, but I think aTuple[Dict[str, Any], List[Tuple[str, str, float]]]is not really something the common person is going to want - but it is what I need to do to fix this.So the question is whether I can just axe this from utils or not. There’s benefits to having a “given a graph give me a basic edge list” but for all I know there’s like 15 different versions of that behavior already. So I figured I’d bring it up with you and see if you have a preference for what we do; axe it from utils or give everyone the
Tuple[Dict[str, Any], List[Tuple[str, str, float]]]return type, which… doesn’t seem super useful. Or, I guess, replicate the function and have a private leiden specific version that does that.