ipywidgets
                                
                                 ipywidgets copied to clipboard
                                
                                    ipywidgets copied to clipboard
                            
                            
                            
                        math.inf / float('inf') do not work with `BoundedFloatText`
I've tried all the following methods to create a LowerOnlyBoundedFloatText, but they all seem to throw one error or the other.
import ipywidgets as ipyw
import math
import numpy as np
import decimal
ipyw.BoundedFloatText(
            value=0,
            min=0,
            max=float('inf'), # math.inf, np.inf, decimal.Decimal('infinity'), None
            disabled=False,
        )
Any suggestions?
I think it isn't implemented. If you want to submit a pr, I think supporting None might be easiest, since I don't think that inf serializes to json.
@jasongrout It appears by default float('inf') is used if max is not provided – this is in the traitlets package [1].
Also, inf serializes to Infinity when using the standard library json.
import json
json.dumps({'x': float('inf')})
# '{"x": Infinity}'
And Javascript also supports Infinity. Using None may be more challenging.
JSON does not support +/- infinity or NaN. They could of course be serialized to strings, but they will then require deserializing.
C.f.: https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript
Also c.f. the json spec: http://www.json.org/
And I tried it again in Chrome:
> JSON.parse('{"x": Infinity}')
Uncaught SyntaxError: Unexpected token I in JSON at position 6
    at JSON.parse (<anonymous>)
    at <anonymous>:1:6
That said, Python does have an option to have proper IEEE float support: see the allow_nan argument at https://docs.python.org/2/library/json.html#basic-usage
Just run into this issue - supporting None as an alternative would be helpful - in the current version it's possible to set the values to inf, but the widget breaks (somehow sets the value to None, guessing that the inf gets turned into a JS undefined somewhere)
If anyone wants to implement this using None, that would likely be accepted. :)
This is a related issue in ipykernel/jupyter_client: https://github.com/jupyter/jupyter_client/pull/708