How to solve Python OSMNX error message: TypeError: unhashable type: 'dict'

313 views Asked by At

My previous script using OSMNX from Geoff boeing is not working anymore since I did Conda update. It used to run before. This is the bare part of the script that gives the error message

import osmnx as ox
import pandas as pd
import geopandas as gpd
import networkx as nx
import numpy as np


# Set place and language;  It must return a POLYGON/POLYLINE, not a POINT, so you might have to play with it a little, or set which_result below accordingly    
place='ALmere, Netherlands'

# note the which_result parameter, as per comment above. Default which_result=1. For places like Utrecht changing it gives a different result
G = ox.graph_from_place(place, network_type='all', which_result=1) 

# For the colouring, we take the attributes from each edge found extract the road name, and use the function above to create the colour array
edge_attributes = ox.graph_to_gdfs(G, nodes=False)

Gives error message:

TypeError: unhashable type: 'dict'

I seem to have the last version of Osmnx (conda list shows 0.16.1). I did find this question, but can't translate that to my code: TypeError: unhashable type: 'dict' in Networkx random walk code that was previously working

And this one: https://github.com/gboeing/osmnx/issues/372. My Python version is 3.8.5

Traceback below:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-6a868604da3b> in <module>
     10 
     11 # note the which_result parameter, as per comment above. Default which_result=1. For places like Utrecht changing it gives a different result
---> 12 G = ox.graph_from_place(place, network_type='all', which_result=1)
     13 
     14 # For the colouring, we take the attributes from each edge found extract the road name, and use the function above to create the colour array

~\Anaconda3\lib\site-packages\osmnx\core.py in graph_from_place(query, network_type, simplify, retain_all, truncate_by_edge, name, which_result, buffer_dist, timeout, memory, max_query_area_size, clean_periphery, infrastructure, custom_filter)
   1443                            max_query_area_size=max_query_area_size,
   1444                            clean_periphery=clean_periphery, infrastructure=infrastructure,
-> 1445                            custom_filter=custom_filter)
   1446 
   1447     log('graph_from_place() returning graph with {:,} nodes and {:,} edges'.format(len(list(G.nodes())), len(list(G.edges()))))

~\Anaconda3\lib\site-packages\osmnx\core.py in graph_from_polygon(polygon, network_type, simplify, retain_all, truncate_by_edge, name, timeout, memory, max_query_area_size, clean_periphery, infrastructure, custom_filter)
   1319         G_buffered = create_graph(response_jsons, name=name, retain_all=True,
   1320                                   bidirectional=network_type in settings.bidirectional_network_types)
-> 1321         G_buffered = truncate_graph_polygon(G_buffered, polygon_buffered, retain_all=True, truncate_by_edge=truncate_by_edge)
   1322 
   1323         # simplify the graph topology

~\Anaconda3\lib\site-packages\osmnx\core.py in truncate_graph_polygon(G, polygon, retain_all, truncate_by_edge, quadrat_width, min_num, buffer_amount)
    731 
    732     # find all the nodes in the graph that lie outside the polygon
--> 733     points_within_geometry = intersect_index_quadrats(gdf_nodes, polygon, quadrat_width=quadrat_width, min_num=min_num, buffer_amount=buffer_amount)
    734     nodes_outside_polygon = gdf_nodes[~gdf_nodes.index.isin(points_within_geometry.index)]
    735 

~\Anaconda3\lib\site-packages\osmnx\core.py in intersect_index_quadrats(gdf, geometry, quadrat_width, min_num, buffer_amount)
    678         # drop duplicate points, if buffered poly caused an overlap on point(s)
    679         # that lay directly on a quadrat line
--> 680         points_within_geometry = points_within_geometry.drop_duplicates(subset='node')
    681     else:
    682         # after simplifying the graph, and given the requested network type,

~\Anaconda3\lib\site-packages\pandas\core\frame.py in drop_duplicates(self, subset, keep, inplace, ignore_index)
   5106 
   5107         inplace = validate_bool_kwarg(inplace, "inplace")
-> 5108         duplicated = self.duplicated(subset, keep=keep)
   5109 
   5110         result = self[-duplicated]

~\Anaconda3\lib\site-packages\pandas\core\frame.py in duplicated(self, subset, keep)
   5245 
   5246         vals = (col.values for name, col in self.items() if name in subset)
-> 5247         labels, shape = map(list, zip(*map(f, vals)))
   5248 
   5249         ids = get_group_index(labels, shape, sort=False, xnull=False)

~\Anaconda3\lib\site-packages\pandas\core\frame.py in f(vals)
   5220         def f(vals):
   5221             labels, shape = algorithms.factorize(
-> 5222                 vals, size_hint=min(len(self), _SIZE_HINT_LIMIT)
   5223             )
   5224             return labels.astype("i8", copy=False), len(shape)

~\Anaconda3\lib\site-packages\pandas\core\algorithms.py in factorize(values, sort, na_sentinel, size_hint)
    676 
    677         codes, uniques = _factorize_array(
--> 678             values, na_sentinel=na_sentinel, size_hint=size_hint, na_value=na_value
    679         )
    680 

~\Anaconda3\lib\site-packages\pandas\core\algorithms.py in _factorize_array(values, na_sentinel, size_hint, na_value, mask)
    499     table = hash_klass(size_hint or len(values))
    500     uniques, codes = table.factorize(
--> 501         values, na_sentinel=na_sentinel, na_value=na_value, mask=mask
    502     )
    503 

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.factorize()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable._unique()

TypeError: unhashable type: 'dict'
0

There are 0 answers