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.

ValueError: Out of range float values are not JSON compliant version 0.12.5

See original GitHub issue

Summary

Issue on versions 0.12.5 when plotting data with patches. Error code is ValueError: Out of range float values are not JSON compliant.

Expected behavior

When using version 0.12.4 of the package the plotting works without any issue. This has been previously brought up in #5439 and fixed with #5544. It seems that this has broken from version 0.12.4 to 0.12.5.

Software

OS

Windows 7 Enterprise

Browser
  • Chrome Version 58.0.3029.81
Python
  • bokeh=0.12.5=py35_0
  • jinja2=2.9.6=py35_0
  • markupsafe=0.23=py35_2
  • mkl=2017.0.1=0
  • numpy=1.12.1=py35_0
  • pandas=0.19.2=np112py35_1
  • pip=9.0.1=py35_1
  • python=3.5.3=0
  • python-dateutil=2.6.0=py35_0
  • pytz=2017.2=py35_0
  • pyyaml=3.12=py35_0
  • requests=2.13.0=py35_0
  • setuptools=27.2.0=py35_1
  • six=1.10.0=py35_0
  • tornado=4.4.2=py35_0
  • vs2015_runtime=14.0.25123=0
  • wheel=0.29.0=py35_0
  • pip:
    • pyshp==1.2.11

Code example

from bokeh.plotting import figure, show, output_notebook
from bokeh.models import HoverTool, ColumnDataSource
import itertools
import shapefile
import pandas as pd
import datetime
import requests
import zipfile
try:
    from StringIO import StringIO
except ImportError:
    from io import BytesIO as StringIO
import os

# Get World Country Map Data
# http://www.naturalearthdata.com/features/
shp = None
dbf = None
url = 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip'
response = requests.get(url)
with zipfile.ZipFile(StringIO(response.content)) as z:
    for fname in z.namelist():
        name, ext = os.path.splitext(fname)
        if ext == '.shp':
            shp = StringIO(z.read(fname)) 
            #shp = z.open(fname)
        elif ext == '.dbf':
            #dbf = z.open(fname)
            dbf = StringIO(z.read(fname))             
        else:
            pass
sf = shapefile.Reader(shp=shp, dbf=dbf)

# Munge map data for bokeh 
lats = []
lons = []
country = []
for shprec in sf.shapeRecords():
    name_long = str(shprec.record[18])
    country.append(name_long)
    lat, lon = map(list, zip(*shprec.shape.points))
    indices = shprec.shape.parts.tolist()
    lat = [lat[i:j] + [float('NaN')] for i, j in zip(indices, indices[1:]+[None])]
    lon = [lon[i:j] + [float('NaN')] for i, j in zip(indices, indices[1:]+[None])]
    lat = list(itertools.chain.from_iterable(lat))
    lon = list(itertools.chain.from_iterable(lon))
    lats.append(lat)
    lons.append(lon)

df = pd.DataFrame({'x': lats, 'y': lons, 'country': country})
cds = ColumnDataSource(df)
p = figure(width=800)
country_patches = p.patches('x', 'y', source=cds, line_color='white')
hover = HoverTool(renderers=[country_patches], tooltips=[('Country', '@country')])
p.add_tools(hover)
show(p)

Taken from Sean law at https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/F-DD-wzOevY

Traceback

Traceback (most recent call last): File "P:\Work\Projects\Capacity Planning\Capacity Planning\test_bokeh\better_us_map_5.py", line 85, in <module> show(p) File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\site-packages\bokeh\io.py", line 284, in show return _show_with_state(obj, _state, browser, new, notebook_handle=notebook_handle) File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\site-packages\bokeh\io.py", line 314, in _show_with_state _show_file_with_state(obj, state, new, controller) File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\site-packages\bokeh\io.py", line 319, in _show_file_with_state filename = save(obj, state=state) File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\site-packages\bokeh\io.py", line 367, in save _save_helper(obj, filename, resources, title) File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\site-packages\bokeh\io.py", line 422, in _save_helper html = file_html(obj, resources, title=title) File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\site-packages\bokeh\embed.py", line 416, in file_html (docs_json, render_items) = _standalone_docs_json_and_render_items(models) File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\site-packages\bokeh\embed.py", line 740, in _standalone_docs_json_and_render_items docs_json[k] = v.to_json() File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\site-packages\bokeh\document.py", line 734, in to_json doc_json = self.to_json_string() File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\site-packages\bokeh\document.py", line 763, in to_json_string return serialize_json(json, indent=indent) File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\site-packages\bokeh\core\json_encoder.py", line 226, in serialize_json return json.dumps(obj, cls=BokehJSONEncoder, allow_nan=False, indent=indent, separators=separators, sort_keys=True, **kwargs) File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\json\__init__.py", line 237, in dumps **kw).encode(obj) File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\json\encoder.py", line 198, in encode chunks = self.iterencode(o, _one_shot=True) File "D:\Users\corey.ducharme\Anaconda\envs\bokeh\lib\json\encoder.py", line 256, in iterencode return _iterencode(o, 0) ValueError: Out of range float values are not JSON compliant

Attempts

I’ve tried debugging the issue further by looking at changes between version on Github, but my inexperience does not let allow me to research this issue in any depth. I hope I’ve been precise enough in my post, but please let me know if you need any further help or clarification : I’m still new to how Github functions. Best of luck on the project.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
DuCoreycommented, May 2, 2017

Okay, thanks for the help bryevdv. You were correct. Using lats = [np.asarray(i) for i in lats] in this example fixes the issue.

0reactions
mikepurviscommented, Feb 23, 2018

My data is a list of scatter point pairs where some are (nan, nan). I plot this like so:

print repr(data)
fig.line(*zip(*data))

For the working data, I see:

[(450.0512595176697, 0.8252045919523492), (450.09909653663635, 0.8252045919515891), ... ]

For the non-working data, it is instead:

array([[ 450.01842856,    0.73487775],
       [ 450.03851318,    0.73487775],
       [ 450.05862641,    0.74477408],
       ..., 
       [ 527.10611415,    0.        ],
       [ 527.12610149,    0.        ],
       [ 527.149261  ,    0.        ]])

If it would be helpful to do so, I could dump this data into a pastebin somewhere.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bokeh: ValueError: Out of range float values are not JSON ...
ValueError : Out of range float values are not JSON compliant. if i change the first value of the list (myList[0]) to float...
Read more >
ValueError: Out of range float values are not JSON compliant ...
Hello, i'm getting and error with show(p, notebook_handle=True), with show(p) it's ok, using 0.12.3 May provide more details if necessary, ...
Read more >
Out of range float values are not JSON compliant
makes error. So, we have to change Nan to another value. In my case, i change the value from Nan to ''(empty string)....
Read more >
Out of range float values are not JSON compliant: nan - Reddit
I'm working with a pretty massive dataset of real estate transactions and I'm trying to make it all fit into a nice little...
Read more >
python-bokeh-0.12.15-bp150.1.3 - SUSE Package Hub -
+ #7523 Out of range float values are not json compliant with numpy arrays + #7537 Export_png does not clean up temporary files...
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