Bug with pie colors in sc.pl.scanpy
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 779
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 27
Description
It works fine when I set the color to 'seurat_clusters'. But I want to show the pie chart for each node so I changed the color parameter according to the format in the documentation. This caused a "unhashable type: 'dict'" error. I looked into the paga.py code but couldn't figure out where the problem is.
The 'seurat_clusters' contains 8 clusters:
adata.obs['seurat_clusters'].cat.categories
Index(['0', '1', '2', '3', '4', '5', '6', '7'], dtype='object')
My command-line to run pl.paga with pie nodes:
sc.pl.paga(adata,color={'0':{'red':0.2,'blue':0.8},'1':{'red':0.2,'blue':0.8},'2':{'red':0.2,'blue':0.8},'3':{'red':0.2,'blue':0.8},'4':{'red':0.2,'blue':0.8},'5':{'red':0.2,'blue':0.8},'6':{'red':0.2,'blue':0.8},'7':{'red':0.2,'blue':0.8}}, root=3, layout='eq_tree', node_size_scale=2, save='PAGA_tree.pdf')
Error message:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-327-1f686f2dc40b> in <module>()
----> 1 sc.pl.paga(adata,color=colors)
/nfs/med-bfx-activeprojects/weishwu/common/Anaconda3/envs/scanpy/lib/python3.6/site-packages/scanpy/plotting/_tools/paga.py in paga(adata, threshold, color, layout, layout_kwds, init_pos, root, labels, single_component, solid_edges, dashed_edges, transitions, fontsize, fontweight, fontoutline, text_kwds, node_size_scale, node_size_power, edge_width_scale, min_edge_width, max_edge_width, arrowsize, title, left_margin, random_state, pos, normalize_to_color, cmap, cax, colorbar, cb_kwds, frameon, add_pos, export_to_gexf, use_raw, colors, groups, plot, show, save, ax)
474 or (c in var_names)
475 )
--> 476 for c in colors
477 ]
478 else:
/nfs/med-bfx-activeprojects/weishwu/common/Anaconda3/envs/scanpy/lib/python3.6/site-packages/scanpy/plotting/_tools/paga.py in <listcomp>(.0)
474 or (c in var_names)
475 )
--> 476 for c in colors
477 ]
478 else:
/nfs/med-bfx-activeprojects/weishwu/common/Anaconda3/envs/scanpy/lib/python3.6/site-packages/pandas/core/indexes/base.py in __contains__(self, key)
4069 False
4070 """
-> 4071 hash(key)
4072 try:
4073 return key in self._engine
TypeError: unhashable type: 'dict'
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in scanpy/plotting/_tools/paga.py, especially the color handling around the traceback at line 476, and reproduce the issue with the provided sc.pl.paga command. Check how the documented per-node color dictionaries are processed before pandas membership checks. Done means the documented pie-node color input runs without the unhashable-dict error and produces the requested PAGA plot.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100