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

Allow wider range of int-like types in NumberInput #1087

Merged

Conversation

nthmost
Copy link
Contributor

@nthmost nthmost commented Feb 11, 2020

Issue: #1065

Description:

Currently, in st.number_input, we overzealously check for pure int types. However, people feed numpy int64, int32, and presumably other int-like types.

This PR introduces the use of numbers.Integral to check whether a number is an int-like type.


Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@nthmost nthmost requested a review from a team as a code owner February 11, 2020 21:51
@johnurbanik
Copy link

johnurbanik commented Feb 11, 2020

Unfortunately, I believe this won't work on Python2 because numpy only started registering int64/int32 in np==1.9.0, but dropped support for Python2 in 1.7.0.

numpy/numpy#2951

You could instead check isinstance(x, (np.int32, np.int64, int,)) (perhaps make that tuple a constant somewhere that can be updated if more types are necessary), or branch between these two paths based on sys.version_info

@nthmost
Copy link
Contributor Author

nthmost commented Feb 11, 2020

Unfortunately, I believe this won't work on Python2 because numpy only started registering int64/int32 in np==1.9.0, but dropped support for Python2 in 1.7.0.

numpy/numpy#2951

You could instead check isinstance(x, (np.int32, np.int64, int,)) (perhaps make that tuple a constant somewhere that can be updated if more types are necessary), or branch between these two paths based on sys.version_info

That's totally fine since we're not supporting Python2 anymore! Thanks (truly) for this comment!

@johnurbanik
Copy link

Unfortunately, I believe this won't work on Python2 because numpy only started registering int64/int32 in np==1.9.0, but dropped support for Python2 in 1.7.0.
numpy/numpy#2951
You could instead check isinstance(x, (np.int32, np.int64, int,)) (perhaps make that tuple a constant somewhere that can be updated if more types are necessary), or branch between these two paths based on sys.version_info

That's totally fine since we're not supporting Python2 anymore! Thanks (truly) for this comment!

Good to know - makes complete sense from a maintainability perspective 👍.

Perhaps it would be advisable to change the documentation to mention this? I just found https://discuss.streamlit.io/t/streamlit-will-deprecate-python-2-in-february/1656, which isn't SEO discoverable and doesn't come up when searching discuss.streamlet.io for 'Python2' or 'Python-2.'

@nthmost
Copy link
Contributor Author

nthmost commented Feb 12, 2020

Perhaps it would be advisable to change the documentation to mention this? I just found https://discuss.streamlit.io/t/streamlit-will-deprecate-python-2-in-february/1656, which isn't SEO discoverable and doesn't come up when searching discuss.streamlet.io for 'Python2' or 'Python-2.'

Yes, that's definitely on our roadmap. This whole month we're in a transition state between py 2/3 and only-3 support. (And I'm the steward of that transition, as it turns out.) Thanks for the observation, it is definitely useful!

@nthmost nthmost merged commit cd95986 into streamlit:develop Feb 12, 2020
sthagen added a commit to sthagen/streamlit-streamlit that referenced this pull request Feb 12, 2020
Allow wider range of int-like types in NumberInput (streamlit#1087)
tvst pushed a commit to tvst/streamlit that referenced this pull request Feb 13, 2020
* test value integer types inclusive of numpy int64, int32, etc

* check all params as numbers.Integer (not just int)

* be more accepting of int types in JSNumber
tvst added a commit that referenced this pull request Feb 16, 2020
* Slider Unit test (#1052)

* Moving balloons e2e to unit test

* Slider unit test

* Testing bounds

* Adding comment for the await timeout

* Set a classname prefix for atomic styletron css classes (#1047)

- fix css conflict between plotly and baseweb slider

* Audio unit test (#1058)

* Make TSC happy (#1067)

* Custom hashing logic for numpy.ufunc types (#1066)

* Adding custom hashing logic for np.ufunc

* added comment and changed np to numpy

* review comments

* Fix a couple Python 3.5 regressions caught in other work: (#1070)

o f-strings is a 3.6 feature
o 3.5 doesn't support a trailing comma after "**kwargs" at the end of a
  function definition.

* Fixing add_rows index calculation (#1054)

* Fixing index computation on add_rows

* linter

* snapshots

* reverting snapshot

* reverting snapshot

* new snapshot from circleci ssh

* Advanced caching updates feb (#1040)

* Updating caching section in main concepts.

* Moving Caching doc over from Google with minor contextual edits. Another pass is still needed. There are placeholders for advanced caching and troubleshooting documents.

* Caching issues is still incomplete.

* Removing content for push later today. Will add advanced and caching issues next rev.

* Addressing Amanda's comments.

* Update

* Advanced caching and issues.

* Edits requested by Thiago

* Fixing link

* Adjusting main concepts to match the google docs section verbatim

* Small tweaks: renamed "items" → "components" and changed verb tenses here and there

* Forgot one verb tense change

* Rename "items" → "components"

* Update PR directly instead of commenting.

Co-authored-by: Thiago Teixeira <thiagot@gmail.com>

* Fix for the CORS check (#965)

* Adding CORS to troubleshooting guide. (#1001)

* Adding CORS to troubleshooting guide.

* Fixing CORS issues from Thiago.

* Changing tip to note.

* Separate common issues into multiple docs and improve them.

* Talk about S4T

Co-authored-by: Thiago Teixeira <thiagot@gmail.com>

* Improve docs (#1075)

* Improve docs.

* Apostrophes

* Add CircleCI jobs to run the oldest and newest Python versions we support. (#1053)

As part of this, we've removed the per-Python-version lib/Pipfile.locks/
files in favor of running without pipenv lock files, and having CircleCI
cache our Python environment using a combination of the Python binary,
lib/Pipfile, and the current data.

This implies that once per day we'll potentially upgrade our Python
packages, consistent with any requirements in lib/Pipfile. We will
always regenerate our Python environment if lib/Pipfile changes,
potentially upgrading any other packages at that time as well. This was
deemed acceptable in a conversation with @tvst.

This also introduces tests.testutils.requires_tensorflow(), a decorator
for tests that require Tensorflow, so that we can skip these under
Python 3.8, which Tensorflow does not yet support.

In doing this work, it was discovered that we had broken our support for
Python 3.5. This required two fixes:

o Invocations of "black" were modified to tell it that it needs
  to retain support for Python 3.5 syntax, which does not permit a
  trailing comma after "**kwargs" in a function definition. Fixed this in
  two places in DeltaGenerator.py, restoring Python 3.5 support.

o In e2e/scripts/st_magic.py, tests of async generators were made
  conditional on Python 3.6 or greater.

Following this change I expect one follow-up commit, and I made a few
voluntary style changes:

o Once this makes it to master, I expect to change the
  "fully-specified" job from python-3.7.4 to python-3.8, leaving only
  one "inheriting" job at 3.5. Not doing this yet so we can get the new
  name passing before we change out GitHub status checks to reference it.

o The new job names reference the Python major and minor versions they
  belong to, but *not* the micro version (e.g., 4 in 3.7.4). I think we
  should be able to advance along these micro/maintenance releases
  without switching job names.

o In the new 3.5 and 3.8 jobs, I removed explicit selection of the
  Debian version underlying the circleci Debian image we run the tests
  under. I could just have easily switched these to "buster", the new
  latest Debian, but I think it's probably better to just go with
  CircleCI's defaults rather than having to remember to check and update
  this every year or so.

o Moved jstests to run against 3.8, since I'm planning to retire testing
  against 3.7 soon per the above. I tried doing this with Cypress as
  well, but ran against diffs due to font differences, so I fell back.

* [mypy] First phase of work on testing Python type annotations. (#1079)

o Introduces lib/mypy.ini with a starter set of strictness options.
o All changes required to make these options pass.
o scripts/mypy created to control running mypy based on suggestion at
  https://mypy.readthedocs.io/en/latest/existing_code.html#continuous-integration.
o scripts/mypy --report emits a "coverage" report, with a summary % at
  the bottom detailing what % of our non-empty/comment source lines have
  full type information. Currently at 19.92%, probably based largely on
  assignments from literals.
o 'scripts/mypy --report' is hooked into CircleCI under the python-3.8
  job. lib/mypy.ini makes it enforce 3.5-compatible syntax, so I see no
  reason not to run it under our latest Python version only.
o In CircleCI, I modified generation of ~/protobuf.md5 that's used for
  cache key generation to also include vary if our protoc or
  protoc-gen-mypy binaries change, as otherwise we'd currently think the
  prior cache was valid without producing .pyi files.

* Widgets unit tests (#1077)

* Checkbox unit test

* Checkbox unit test

* DateInput unit test foundations

* DateInput unit test

* Multiselect unit test

* Testing multiselect overrides

* Radio unit test

* Selectbox unit test

* TextArea unit test

* TextArea unit test

* TextArea unit test

* TextInput unit tests

* TimeInput test

* Removing unused var

* Fixing date

* Fixing date

* Fix indentation error in fad994c. (#1084)

* Fix an incomplete copy for a dict that's then modified. (#1078)

New test fails before the change, and passes afterwards.

* Handle different Caching error messages (#1068)

* handle internal and user errors during hashing
* update hashing error messages and traceback handling
* add filename and lineno to user hash error message

* Retire python-3.7.4 CircleCI project. (#1086)

We'll retain testing only against our oldest (3.5) and newest (3.8)
supported Python versions going forward.

FWIW, the "cypress" test continues to be based on a 3.7.4 image because
efforts to upgrade under #1053
failed due to font rendering differences with screenshots. Handling this
upgrade, when needed, will be performed separately, but should not block
removal of running the whole Python suite against 3.7.4.

* Version 0.55.1 (just pointing to new docs) (#1089)

* Fix links in docs.

* Point Streamlit caching error messages to the right URLs

* Improve docs (#1075)

* Improve docs.

* Apostrophes

* Lint

* Update version to 0.55.1

* Fix update_version.py to point to correct md file

* Somehow the changelog for 0.55 got lost. Fixed.

* Somehow the changelog for 0.55 got lost. Fixed.

* Remove old advanced caching section from advanced_concepts.md

* Fix missing caching URL (#1094)

* Allow wider range of int-like types in NumberInput (#1087)

* test value integer types inclusive of numpy int64, int32, etc

* check all params as numbers.Integer (not just int)

* be more accepting of int types in JSNumber

* Fix signatures of wrapped DG functions

* Lint

* Fix bug where icon assets were missing from "make install"

* Ugly hack: name screencast files foo.webm.mp4 so it works on sites like Twitter with no modification.

* Version 0.56.0

* Add logs to caching/hashing

* In hashing.py, only import numpy when needed

* Lint

* Unbreak audio component

* Fix audio tests

* Chmod -x all .ts(x) files

* Block Streamlit installation if Python < 3.5

* Force Python >= 3.5

* Update snaps.

* Update headers and notices

* Update changelog

* Forgot to add emojis to changelog!

* Fix bad merge with audio.test.tsx

Co-authored-by: Nahuel Emiliano Rosso Fandiño <arraydude@gmail.com>
Co-authored-by: Jonathan Rhone <rhone.j@gmail.com>
Co-authored-by: Henrikh Kantuni <henrikh.kantuni@gmail.com>
Co-authored-by: Matteo <monchier@users.noreply.github.com>
Co-authored-by: Nate White <whiten@georgetown.edu>
Co-authored-by: erikhopf <erik.hopf@gmail.com>
Co-authored-by: Jackie <52658745+1wpro2@users.noreply.github.com>
Co-authored-by: Naomi Most <pnaomi@gmail.com>
tconkling added a commit to tconkling/streamlit that referenced this pull request Feb 18, 2020
* develop: (29 commits)
  Release 0.56.0 (streamlit#1101)
  Fix bug where icon assets were missing from "make install" (streamlit#1100)
  Clean signatures of wrapped DeltaGenerator methods (streamlit#1099)
  Using widgetId as the key when rendering elements (streamlit#1102)
  Pass --skip-lock to pipenv under pipenv-install Makefile target. (streamlit#1093)
  Allow wider range of int-like types in NumberInput (streamlit#1087)
  Fix missing caching URL (streamlit#1094)
  Version 0.55.1 (just pointing to new docs) (streamlit#1089)
  Retire python-3.7.4 CircleCI project. (streamlit#1086)
  Handle different Caching error messages (streamlit#1068)
  Fix an incomplete copy for a dict that's then modified. (streamlit#1078)
  Fix indentation error in fad994c. (streamlit#1084)
  Widgets unit tests (streamlit#1077)
  [mypy] First phase of work on testing Python type annotations. (streamlit#1079)
  Add CircleCI jobs to run the oldest and newest Python versions we support. (streamlit#1053)
  Improve docs (streamlit#1075)
  Adding CORS to troubleshooting guide. (streamlit#1001)
  Fix for the CORS check (streamlit#965)
  Advanced caching updates feb (streamlit#1040)
  Fixing add_rows index calculation (streamlit#1054)
  ...
tconkling added a commit to tconkling/streamlit that referenced this pull request Feb 19, 2020
* develop: (30 commits)
  [Screencast] Fixing countdown bug (streamlit#1082)
  Release 0.56.0 (streamlit#1101)
  Fix bug where icon assets were missing from "make install" (streamlit#1100)
  Clean signatures of wrapped DeltaGenerator methods (streamlit#1099)
  Using widgetId as the key when rendering elements (streamlit#1102)
  Pass --skip-lock to pipenv under pipenv-install Makefile target. (streamlit#1093)
  Allow wider range of int-like types in NumberInput (streamlit#1087)
  Fix missing caching URL (streamlit#1094)
  Version 0.55.1 (just pointing to new docs) (streamlit#1089)
  Retire python-3.7.4 CircleCI project. (streamlit#1086)
  Handle different Caching error messages (streamlit#1068)
  Fix an incomplete copy for a dict that's then modified. (streamlit#1078)
  Fix indentation error in fad994c. (streamlit#1084)
  Widgets unit tests (streamlit#1077)
  [mypy] First phase of work on testing Python type annotations. (streamlit#1079)
  Add CircleCI jobs to run the oldest and newest Python versions we support. (streamlit#1053)
  Improve docs (streamlit#1075)
  Adding CORS to troubleshooting guide. (streamlit#1001)
  Fix for the CORS check (streamlit#965)
  Advanced caching updates feb (streamlit#1040)
  ...
tconkling added a commit to tconkling/streamlit that referenced this pull request Feb 24, 2020
* develop: (53 commits)
  Update plotly.js to 1.52 (streamlit#1119)
  Add tooltip in Altair/Vega-lite docstring code (streamlit#1092)
  Ability to bind to a server address with server.address config option (streamlit#1107)
  [mypy] Enable check_untyped_defs throughout the codebase. (streamlit#1110)
  st.map: set "radiusMinPixels" to 3 (streamlit#1113)
  st.plotly_chart docs incorrectly refer to Altair (streamlit#1118)
  Fix BytesIO and numpy array data sources for audio/video (streamlit#1116)
  Show warning to user and use skipkeys=True if json.dumps causes TypeError (streamlit#1112)
  Server: store SessionInfo by id (streamlit#1056)
  [Screencast] Fixing countdown bug (streamlit#1082)
  Release 0.56.0 (streamlit#1101)
  Fix bug where icon assets were missing from "make install" (streamlit#1100)
  Clean signatures of wrapped DeltaGenerator methods (streamlit#1099)
  Using widgetId as the key when rendering elements (streamlit#1102)
  Pass --skip-lock to pipenv under pipenv-install Makefile target. (streamlit#1093)
  Allow wider range of int-like types in NumberInput (streamlit#1087)
  Fix missing caching URL (streamlit#1094)
  Version 0.55.1 (just pointing to new docs) (streamlit#1089)
  Retire python-3.7.4 CircleCI project. (streamlit#1086)
  Handle different Caching error messages (streamlit#1068)
  ...
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.

None yet

3 participants