question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unicode issue in tooltips on Jupyter notebook

See original GitHub issue

image

MVP:

import folium
map_osm = folium.Map()
folium.GeoJson('{ "type": "Feature", "properties": { "name": "5/7, Линейная улица, Berdsk, Berdsk municipality, Novosibirsk Oblast, Siberian Federal District, 633011, Russia" }, "geometry": { "type": "Point", "coordinates": [ -75.849253579389796, 47.6434349837781 ] }}', name="5/7, Линейная улица, Berdsk, Berdsk municipality, Novosibirsk Oblast, Siberian Federal District, 633011, Russia", tooltip="5/7, Линейная улица, Berdsk, Berdsk municipality, Novosibirsk Oblast, Siberian Federal District, 633011, Russia").add_to(map_osm)
display(map_osm)

I’m running in Jupyter Lab with Python3.7 and latest Folium version (0.10.1+28.ga8ec61d which is with my PR)

Is there a workaround for this?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:11

github_iconTop GitHub Comments

12reactions
Conengmocommented, Jun 18, 2020

A fix has been merged in the branca library. It will be availabe in the next release, release date yet unknown. If you want it earlier you can install branca from the git main branch:

pip install git+https://github.com/python-visualization/branca.git@master

5reactions
Conengmocommented, May 8, 2020

I think I found the issue. In branca we encode the html for in the notebook. This uses encode('utf-8'). A unicode string like "5/7, Линейная улица, Berdsk" is turned into bytes b'5/7, \xd0\x9b\xd0\xb8\xd0\xbd\xd0\xb5\xd0\xb9\xd0\xbd\xd0\xb0\xd1\x8f \xd1\x83\xd0\xbb\xd0\xb8\xd1\x86\xd0\xb0, Berdsk'. This is then base64 encoded.

When the notebook rehydrates this code it uses atob to do base64 decoding. This function does not convert those characters to the right representations: Ð\u009bинейнаÑ\u008f Ñ\u0083лиÑ\u0086а. I’m no expert on JS but I think it uses a default charset of utf-16.

The solution is to encode the html not as utf-8, but using raw_unicode_escape. This converts "5/7, Линейная улица, Berdsk" into b'5/7, \\u041b\\u0438\\u043d\\u0435\\u0439\\u043d\\u0430\\u044f \\u0443\\u043b\\u0438\\u0446\\u0430, Berdsk' which results in proper dehydrated html in the browser.

I’ll open a PR in branca with this fix. You could really help by testing that fix!

Read more comments on GitHub >

github_iconTop Results From Across the Web

pygal charts not displaying tooltips in Jupyter / IPython notebook
My workaround involved setting up the HTML with the necessary javascript and chart svg like so: import pygal from IPython.display import ...
Read more >
Tab Completion & Tooltip shortcut in Jupyter Notebook
Jupyter Notebook Tips and Tricks | Tab Completion & Tooltip shortcut in Jupyter NotebookShortcut for 1. Tab2. Shift + Tab Key3.
Read more >
Jupyter Notebook Documentation, Release 6.5.0.dev0
Remove deprecated encoding parameter for Python 3.9 compatibility. ... Tooltips visible through keyboard navigation for specified buttons ...
Read more >
Tooltip Encoding Issue - ADocLib
Describe the bug When hovering over a function there is a tooltip shown which contains ... Unicode issue in tooltips on Jupyter notebook...
Read more >
0.13 Series — IPython 3.2.1 documentation
The IPython Notebook, which has proven since its release to be wildly ... While this hides all error reporting, once you have a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found