kraina-ai / srai

Spatial Representations for Artificial Intelligence - a Python library toolkit for geospatial machine learning focused on creating embeddings for downstream tasks
https://kraina-ai.github.io/srai/
Apache License 2.0
220 stars 17 forks source link

'list' object has no attribute 'discard' #431

Closed vhvictorhugo closed 7 months ago

vhvictorhugo commented 8 months ago

I'm trying to execute the hex2vec_embedder.ipynb notebook, but the follow error appears when i execute all the notebook (without any changes):

OBS: the error appears in the cell that generate region embeddings, i. e., before viewing the embeddings' similarity.

File ~/.local/lib/python3.10/site-packages/srai/neighbourhoods/_base.py:161, in Neighbourhood._handle_center(self, index, distance, neighbours, at_distance, include_center_override)

159 neighbours.add(index) 160 else: --> 161 neighbours.discard(index) 162 return neighbours

AttributeError: 'list' object has no attribute 'discard'

I've been looking to this function (_handle_center at srai/neighbourhoods/_base.py file) that the problems appear and setting the neighbours variable as python set, like neighbours = set(neighbours) at the beginning of the function and works fine, but i'm reporting this problem because i belive that have another optimized ways to resolve this problem.

This colab notebook contains the complete error code.

vhvictorhugo commented 8 months ago

Captura de tela de 2024-03-23 22-49-06 I'm leaving a print of the solution that i mentioned at the issue.

OBS: the line 145 contains the alteration mentioned.

piotrgramacki commented 8 months ago

Hi @vhvictorhugo, Thanks for letting us know about it. We'll look at it to find a permanent solution, but your solution will give you the correct results. There should be a set there in all cases.

vhvictorhugo commented 8 months ago

Hello, @piotrgramacki! Thanks for your attention! For now i'll continue this way. I'm awaiting for new updates.

piotrgramacki commented 7 months ago

This problem is a result of a change in the h3 library: https://github.com/uber/h3-py/releases/tag/v4.0.0b3 We'll update our library and release a new version soon.

For now, one solution to this problem is to apply the change proposed by @vhvictorhugo. Another one (if you don't want to install srai as an editable package) is to install the previous version of the h3 library with h3==4.0.0b2 in the requirements file.

vhvictorhugo commented 7 months ago

Thanks for feedback @piotrgramacki