TypeError: "Set type is unordered" in OSMnx isochrones example

TypeError: "Set type is unordered" in OSMnx isochrones example

运行 OSMnx isochrones example,在最后一个单元格上出现 TypeError:“Set type is unordered”。

知道出了什么问题吗?

OSMnx 0.15.1 Python 3.8.5,Pandas 1.1.1,GeoPandas 0.8.1.

它在 Pandas 1.0.5 中按预期工作,但在 Pandas 1.1 或 1.1.1

中失败
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
 in 
     26     return isochrone_polys
     27 
---> 28 isochrone_polys = make_iso_polys(G, edge_buff=25, node_buff=0, infill=True)
     29 fig, ax = ox.plot_graph(G, show=False, close=False, edge_color='#999999', edge_alpha=0.2, node_size=0)
     30 for polygon, fc in zip(isochrone_polys, iso_colors):

 in make_iso_polys(G, edge_buff, node_buff, infill)
      5 
      6         node_points = [Point((data['x'], data['y'])) for node, data in subgraph.nodes(data=True)]
----> 7         nodes_gdf = gpd.GeoDataFrame({'id': subgraph.nodes()}, geometry=node_points)
      8         nodes_gdf = nodes_gdf.set_index('id')
      9 

~/miniconda3/envs/osmnx-examples/lib/python3.8/site-packages/geopandas/geodataframe.py in __init__(self, *args, **kwargs)
     87         crs = kwargs.pop("crs", None)
     88         geometry = kwargs.pop("geometry", None)
---> 89         super(GeoDataFrame, self).__init__(*args, **kwargs)
     90 
     91         # need to set this before calling self['geometry'], because

~/miniconda3/envs/osmnx-examples/lib/python3.8/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
    466 
    467         elif isinstance(data, dict):
--> 468             mgr = init_dict(data, index, columns, dtype=dtype)
    469         elif isinstance(data, ma.MaskedArray):
    470             import numpy.ma.mrecords as mrecords

~/miniconda3/envs/osmnx-examples/lib/python3.8/site-packages/pandas/core/internals/construction.py in init_dict(data, index, columns, dtype)
    281             arr if not is_datetime64tz_dtype(arr) else arr.copy() for arr in arrays
    282         ]
--> 283     return arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype)
    284 
    285 

~/miniconda3/envs/osmnx-examples/lib/python3.8/site-packages/pandas/core/internals/construction.py in arrays_to_mgr(arrays, arr_names, index, columns, dtype, verify_integrity)
     81 
     82         # don't force copy because getting jammed in an ndarray anyway
---> 83         arrays = _homogenize(arrays, index, dtype)
     84 
     85         columns = ensure_index(columns)

~/miniconda3/envs/osmnx-examples/lib/python3.8/site-packages/pandas/core/internals/construction.py in _homogenize(data, index, dtype)
    349                     val = dict(val)
    350                 val = lib.fast_multiget(val, oindex._values, default=np.nan)
--> 351             val = sanitize_array(
    352                 val, index, dtype=dtype, copy=False, raise_cast_failure=False
    353             )

~/miniconda3/envs/osmnx-examples/lib/python3.8/site-packages/pandas/core/construction.py in sanitize_array(data, index, dtype, copy, raise_cast_failure)
    450         subarr = _try_cast(arr, dtype, copy, raise_cast_failure)
    451     elif isinstance(data, abc.Set):
--> 452         raise TypeError("Set type is unordered")
    453     elif lib.is_scalar(data) and index is not None and dtype is not None:
    454         data = maybe_cast_to_datetime(data, dtype)

TypeError: Set type is unordered

这是示例中的一个问题。它用 subgraph.nodes()

初始化数据框
nodes_gdf = gpd.GeoDataFrame({'id': subgraph.nodes()}, geometry=node_points)

subgraph.nodes()NodeView, which behaves both like a dictionary and a set. These are unordered types, but Pandas needs an ordered collection such as a numpy array or list. Pandas 1.1 introduced a type check to catch this in issue 32582.

解决方法是将 NodeView 显式转换为 list:


nodes_gdf = gpd.GeoDataFrame({'id': list(subgraph.nodes())}, geometry=node_points)

我提交了一个bug and a PR,已经被接受了,所以这不再是问题。