ValueError: Out of range float values are not JSON compliant version 0.12.5
See original GitHub issueSummary
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:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Okay, thanks for the help bryevdv. You were correct. Using
lats = [np.asarray(i) for i in lats]
in this example fixes the issue.My data is a list of scatter point pairs where some are
(nan, nan)
. I plot this like so:For the working data, I see:
For the non-working data, it is instead:
If it would be helpful to do so, I could dump this data into a pastebin somewhere.