gusye1234 / nano-graphrag

A simple, easy-to-hack GraphRAG implementation
MIT License
1.28k stars 123 forks source link

_remove_dups_flatten出现TypeError: unhashable type: 'list' #7

Closed Zack14159 closed 2 months ago

Zack14159 commented 2 months ago

在执行到await self._clustering_algorithms[algorithm]()的时候出现报错:

from graspologic.partition import hierarchical_leiden File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/site-packages/graspologic/init.py", line 6, in import graspologic.datasets File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/site-packages/graspologic/datasets/init.py", line 4, in from .base import load_drosophila_left, load_drosophila_right, load_mice File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/site-packages/graspologic/datasets/base.py", line 14, in from ..utils import import_edgelist File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/site-packages/graspologic/utils/init.py", line 4, in from .ptr import pass_to_ranks File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/site-packages/graspologic/utils/ptr.py", line 8, in from .utils import import_graph, is_loopless, is_symmetric, is_unweighted, symmetrize File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/site-packages/graspologic/utils/utils.py", line 13, in from beartype import beartype File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/site-packages/beartype/init.py", line 58, in from beartype._decor.decormain import ( File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/site-packages/beartype/_decor/decormain.py", line 26, in from beartype._conf.confcls import ( File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/site-packages/beartype/_conf/confcls.py", line 46, in from beartype._conf.confoverrides import ( File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/site-packages/beartype/_conf/confoverrides.py", line 15, in from beartype._data.hint.datahinttyping import ( File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/site-packages/beartype/_data/hint/datahinttyping.py", line 290, in BeartypeReturn = Union[BeartypeableT, BeartypeConfedDecorator] File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/typing.py", line 244, in inner return func(*args, **kwds) File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/typing.py", line 317, in getitem return self._getitem(self, parameters) File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/typing.py", line 422, in Union parameters = _remove_dups_flatten(parameters) File "/data/newssd/anaconda3/envs/graphrag/lib/python3.9/typing.py", line 216, in _remove_dups_flatten all_params = set(params) TypeError: unhashable type: 'list'

当前params为:[~BeartypeableT, collections.abc.Callable[[~BeartypeableT], ~BeartypeableT]]

params一共在下面几种场景下会出现错误: wrong!!!!! [~BeartypeableT, collections.abc.Callable[[~BeartypeableT], ~BeartypeableT]] unhashable type: 'list'

wrong!!!!! [<class 'type'>, collections.abc.Callable[[], object]] unhashable type: 'list'

wrong!!!!! [collections.abc.Callable[[<class 'int'>], typing.Optional[frame]], <class 'NoneType'>]

对应代码: def _remove_dups_flatten(parameters): """An internal helper for Union creation and substitution: flatten Unions among parameters, then remove duplicates. """

Flatten out Union[Union[...], ...].

params = []
for p in parameters:
    if isinstance(p, _UnionGenericAlias):
        params.extend(p.__args__)
    elif isinstance(p, tuple) and len(p) > 0 and p[0] is Union:
        params.extend(p[1:])
    else:
        params.append(p)
# Weed out strict duplicates, preserving the first of each occurrence.
all_params = set(params)  # 应该是这一句?
if len(all_params) < len(params):
    new_params = []
    for t in params:
        if t in all_params:
            new_params.append(t)
            all_params.remove(t)
    params = new_params
    assert not all_params, all_params
return tuple(params)

报错忽略直接返回tuple(params)似乎也能继续跑下去

gusye1234 commented 2 months ago

看起来是python版本和graspologic库的问题 你的python版本是什么?

Zack14159 commented 2 months ago

我的的python版本是 Python 3.9.0

Zack14159 commented 2 months ago

换成3.10.0以后ok了,不报错了,谢谢老师