holoviz / holoviz/hvplot

nodelist parameter of hvnx.draw raises exception

Open
#762 1 comment 0 reactions 0 assignees View on GitHub
interface: networkx
Dominant language
Python
Stars
1.4k
Forks
124
Avg merge
1d 18h
Merged PRs (30d)
1

Description

Thanks for contacting us! Please read and follow these instructions carefully, then delete this introductory text to keep your issue easy to read. Note that the issue tracker is NOT the place for usage questions and technical assistance; post those at [Discourse](https://discourse.holoviz.org) instead. Issues without the required information below may be closed immediately.

#### ALL software version info
sys.version='3.10.4 (main, Mar 31 2022, 08:41:55) [GCC 7.5.0]'
nx.__version__='2.8.3'
hv.__version__='1.14.9'
hvplot.__version__='0.8.0'

#### Description of expected behavior and the observed behavior
hvnx.draw should be a drop in replacement for nx.draw
but `nodelist` argument does not work properly (see example)

#### Complete, minimal, self-contained example code that reproduces the issue

```
# code goes here between backticks
import hvplot.networkx as hvnx
import numpy as np
import networkx as nx

G = nx.DiGraph()
G.add_edge(100, 120)
G.add_edge(100, 121)
G.add_edge(100, 122)

# nx.draw(G, nodelist=[121, 120]) # works ok
hvnx.draw(G, nodelist=[121, 120]) # raises exception
```

#### Stack traceback and/or browser JavaScript console output
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
File ~/anaconda3/envs/py310/lib/python3.10/site-packages/pandas/core/indexing.py:1482, in _iLocIndexer._get_list_axis(self, key, axis)
1481 try:
-> 1482 return self.obj._take_with_is_copy(key, axis=axis)
1483 except IndexError as err:
1484 # re-raise with different error message

File ~/anaconda3/envs/py310/lib/python3.10/site-packages/pandas/core/generic.py:3716, in NDFrame._take_with_is_copy(self, indices, axis)
3709 """
3710 Internal version of the `take` method that sets the `_is_copy`
3711 attribute to keep track of the parent dataframe (using in indexing
(...)
3714 See the docstring of `take` for full explanation of the parameters.
3715 """
-> 3716 result = self.take(indices=indices, axis=axis)
3717 # Maybe set copy if we didn't actually change the index.

File ~/anaconda3/envs/py310/lib/python3.10/site-packages/pandas/core/generic.py:3703, in NDFrame.take(self, indices, axis, is_copy, **kwargs)
3701 self._consolidate_inplace()
-> 3703 new_data = self._mgr.take(
3704 indices, axis=self._get_block_manager_axis(axis), verify=True
3705 )
3706 return self._constructor(new_data).__finalize__(self, method="take")

File ~/anaconda3/envs/py310/lib/python3.10/site-packages/pandas/core/internals/managers.py:897, in BaseBlockManager.take(self, indexer, axis, verify)
896 n = self.shape[axis]
--> 897 indexer = maybe_convert_indices(indexer, n, verify=verify)
899 new_labels = self.axes[axis].take(indexer)

File ~/anaconda3/envs/py310/lib/python3.10/site-packages/pandas/core/indexers/utils.py:292, in maybe_convert_indices(indices, n, verify)
291 if mask.any():
--> 292 raise IndexError("indices are out-of-bounds")
293 return indices

IndexError: indices are out-of-bounds

The above exception was the direct cause of the following exception:

IndexError Traceback (most recent call last)
Input In [10], in ()
18 G.add_edge(100, 122)
20 # nx.draw(G, nodelist=[121, 120]) # works ok
---> 21 hvnx.draw(G, nodelist=[121, 120])

File ~/anaconda3/envs/py310/lib/python3.10/site-packages/hvplot/networkx.py:231, in draw(G, pos, **kwargs)
228 g = _from_networkx(G, pos, **params)
230 if 'nodelist' in kwargs:
--> 231 g.nodes.data = g.nodes.data.iloc[list(kwargs['nodelist'])]
233 if 'edgelist' in kwargs:
234 edges = g.array([0, 1])

File ~/anaconda3/envs/py310/lib/python3.10/site-packages/pandas/core/indexing.py:967, in _LocationIndexer.__getitem__(self, key)
964 axis = self.axis or 0
966 maybe_callable = com.apply_if_callable(key, self.obj)
--> 967 return self._getitem_axis(maybe_callable, axis=axis)

File ~/anaconda3/envs/py310/lib/python3.10/site-packages/pandas/core/indexing.py:1511, in _iLocIndexer._getitem_axis(self, key, axis)
1509 # a list of integers
1510 elif is_list_like_indexer(key):
-> 1511 return self._get_list_axis(key, axis=axis)
1513 # a single integer
1514 else:
1515 key = item_from_zerodim(key)

File ~/anaconda3/envs/py310/lib/python3.10/site-packages/pandas/core/indexing.py:1485, in _iLocIndexer._get_list_axis(self, key, axis)
1482 return self.obj._take_with_is_copy(key, axis=axis)
1483 except IndexError as err:
1484 # re-raise with different error message
-> 1485 raise IndexError("positional indexers are out-of-bounds") from err

IndexError: positional indexers are out-of-bounds
#### Screenshots or screencasts of the bug in action

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.