Skip to content

Permit entry of non-finite values into float SpinBox#1422

Merged
j9ac9k merged 6 commits intopyqtgraph:masterfrom
lidstrom83:spinbox-inf-nan
Oct 28, 2020
Merged

Permit entry of non-finite values into float SpinBox#1422
j9ac9k merged 6 commits intopyqtgraph:masterfrom
lidstrom83:spinbox-inf-nan

Conversation

@lidstrom83
Copy link
Copy Markdown
Contributor

Bounds are enforced for inf and -inf, but nan ignores them. Attempting to step any of these values doesn't do anything.

A previously existing bug is also fixed where the text is not updated properly when out-of-bounds data is entered.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 27, 2020

Looks like a python2 issue:

    from math import isnan, isfinite
ImportError: cannot import name isfinite

Any reason not to use the numpy.isfinite()?

@lidstrom83
Copy link
Copy Markdown
Contributor Author

Any reason not to use the numpy.isfinite()?

Just a habit of preferring standard library functions when operating on single values. Sometimes the numpy alternatives are much slower when operating on single values. Also, numpy hadn't been imported in this module yet and I didn't want to make it harder to reuse this code without it.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 27, 2020

Truth be told I too have the habit for using the math module for single values, I made that suggestion not knowing there was a good py2/3 compatible function.

SI_PREFIX_EXPONENTS['u'] = -6

FLOAT_REGEX = re.compile(r'(?P<number>[+-]?((\d+(\.\d*)?)|(\d*\.\d+))([eE][+-]?\d+)?)\s*((?P<siPrefix>[u' + SI_PREFIXES + r']?)(?P<suffix>\w.*))?$')
FLOAT_REGEX = re.compile(r'(?P<number>[+-]?((((\d+(\.\d*)?)|(\d*\.\d+))([eE][+-]?\d+)?)|((?i)(nan)|(inf))))\s*((?P<siPrefix>[u' + SI_PREFIXES + r']?)(?P<suffix>\w.*))?$')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding a comment here, you don't need to update the PR (unless you want to) but we should really make use of re.verbose for these more complex regexes.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 28, 2020

Thanks for the PR @lidstrom83 this looks good to me, merging.

@j9ac9k j9ac9k merged commit 0a7a54c into pyqtgraph:master Oct 28, 2020
@lidstrom83 lidstrom83 deleted the spinbox-inf-nan branch December 11, 2020 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants