Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math.inf / float('inf') do not work with BoundedFloatText #1531

Open
kdheepak opened this issue Jul 22, 2017 · 8 comments
Open

math.inf / float('inf') do not work with BoundedFloatText #1531

kdheepak opened this issue Jul 22, 2017 · 8 comments

Comments

@kdheepak
Copy link

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?

@jasongrout
Copy link
Member

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 jasongrout added this to the Future milestone Jul 22, 2017
@kdheepak
Copy link
Author

kdheepak commented Jul 25, 2017

@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.

@vidartf
Copy link
Member

vidartf commented Jul 25, 2017

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

@jasongrout
Copy link
Member

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

@jasongrout
Copy link
Member

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

@mangecoeur
Copy link

mangecoeur commented Nov 26, 2021

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)

@vidartf
Copy link
Member

vidartf commented Nov 30, 2021

If anyone wants to implement this using None, that would likely be accepted. :)

@SylvainCorlay
Copy link
Member

SylvainCorlay commented Dec 1, 2021

This is a related issue in ipykernel/jupyter_client: jupyter/jupyter_client#708

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants