RecursionError: maximum recursion depth exceeded in comparison when coordinates are of type object
See original GitHub issuePlease add a code sample or a nbviewer link, copy-pastable if possible
#!/usr/bin/env python3
import sys
import numpy as np
import pandas as pd
import folium
from folium import plugins
datafile = "/tmp/test.json"
df = pd.read_json(datafile)
stops_map = folium.Map(location=[44.409748, 8.930819], zoom_start=11)
marker_cluster = folium.plugins.MarkerCluster().add_to(stops_map)
counter = 0
for name, row in df.iloc[:].iterrows():
if counter % 10000 == 1:
print(counter, row["latitudine"], row["longitudine"], row["temperatura"])
folium.Marker([row["latitudine"], row["longitudine"]], popup=row["temperatura"]).add_to(marker_cluster)
counter += 1
stops_map.save('/tmp/folium-test.html')
Problem description
I’m quite a python newbie so maybe this could be obvious to most people, but reading a json file (with lot of blanks instead of valid GPS coordinates) and trying to copy from this tutorial leads to a big bold error: RecursionError: maximum recursion depth exceeded in comparison
.
I think this is because variables are passed as objects instead of float64 or other base types.
Adding this code after pd.read_json() converts blanks to valid GPS coordinates and downscales variable types to float64 and folium works as expected.
df['longitudine'] = df['longitudine'].replace(r'\s+', np.nan, regex=True)
df['longitudine'] = df['longitudine'].replace(r'^$', np.nan, regex=True)
df['longitudine'] = df['longitudine'].fillna(-0.99999)
df['longitudine'] = pd.to_numeric(df['longitudine'])
df['latitudine'] = df['latitudine'].replace(r'\s+', np.nan, regex=True)
df['latitudine'] = df['latitudine'].replace(r'^$', np.nan, regex=True)
df['latitudine'] = df['latitudine'].fillna(-0.99999)
df['latitudine'] = pd.to_numeric(df['latitudine'])
Sample output can be found here.
Expected Output
No error, or at least a warning such as “Folium can’t directly work on object types: pass base types such as float64 or expect problems”.
Output of folium.__version__
0.8.3
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
What is the maximum recursion depth in Python, and how to ...
RecursionError : maximum recursion depth exceeded in comparison. Solution : First it's better to know when you execute a recursive ...
Read more >Python maximum recursion depth exceeded in comparison
The Solution. Python has raised a recursion error to protect us against a stack overflow. This is when the pointer in a stack...
Read more >Python: Maximum Recursion Depth Exceeded [How to Fix It]
This error says it all—maximum recursion depth exceeded in comparison. This tells you that Python's recursion depth limit of 1000 is reached.
Read more >maximum recursion depth exceeded in comparison
This gives rise to the following error: RecursionError: maximum recursion depth exceeded. However, if I write a function such as the following:
Read more >Résoudre RecursionError maximum recursion depth exceeded
Bonjour à tous,Quand on code une méthode récursive, il n'est pas rare de rencontrer l'erreur " RecursionError maximum recursion depth ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same issue, in my case, the value in latitude and longitude were string values so I mapped it to float which solved the issue.
@SooluThomas