Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Strange output of "TypeError" of "GeoDataFrame" when only calling the range

I come across a strange error when using range(a, b) in Python, which says I made a TypeError for calling GeoDataFrame, while there should not be any GeoDataFrame involved.

The process should not be related to GeoDataFrame. For example, I tried to print the range(0,2), while getting the TypeError. No error would happen if using the list directly (e.g.[1,2,3])

(The following are my codes for reference. They are generally for generating a network in Python-igraph from shapefiles.)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

# Import packages
import pandas as pd
import geopandas as gpd
import numpy as np
import igraph as ig

# Import data
data = gpd.read_file(r"\streets.shp")
print(data)
data2 = gpd.read_file(r"\intersections.shp")
range = gpd.read_file(r"\streets_range.shp")
OD_matrix = gpd.read_file(r"\OD_data.gpkg", driver="GPKG")

# Make sure the intersection IDs are integers
data["Inter_ID0"] = data["Inter_ID0"].astype(int)
data["Inter_ID1"] = data["Inter_ID1"].astype(int)

# Create graph
G = ig.Graph()
G.add_vertices(data2.shape[0])
G.add_edges(list(zip(data["Inter_ID0"], data["Inter_ID1"])))
G.es['Length'] = data["Length"]

# Calculate shortest paths
for v in range(0, 7506):
    path1 = G.get_shortest_paths(v, to=None, weights="Length", mode='all', output='epath')
    path2 = G.get_shortest_paths(v, to=None, weights="Length", mode='all', output='vpath')
    ......

Results:

TypeError                                 Traceback (most recent call last)
Cell In[4], line 2
      1 matrix = pd.DataFrame([])
----> 2 for v in range(0, 7506):
      3     path1 = G.get_shortest_paths(v, to=None, weights="Length", mode='all', output='epath')
      4     path2 = G.get_shortest_paths(v, to=None, weights="Length", mode='all', output='vpath')

TypeError: 'GeoDataFrame' object is not callable

(So the traceback also did not refer to any line where GeoDataFrame is involved.)

>Solution :

You’re assigning a variable to the keyword range earlier in your code. Change the name of that variable.

streets_range = gpd.read_file(r"\streets_range.shp")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading