Repository: streamlit/streamlit

Issue:
In number_input, min_value & max_value format override format string and raises no warning
# Summary

Regardless of the format string specified by the user, actual format used will be based on min_value and max_value

# Steps to reproduce

The following code presents a warning:
`weight = st.number_input("Today's weight:", min_value=50.0, max_value=750.0, format="%d")`
_Warning: NumberInput value below is float, but format %d displays as integer._

I believe that's intended behavior. However, the inverse condition doesn't produce a warning or error.
```
weight = st.number_input("Today's weight:", min_value=50, max_value=750, format="%4.1f")
print(weight)
st.write("Echoing weight: ", weight)

```
If the input value is, for example, 170.4, the weight value will be 170, shown by both print() and st.write(), based on the interpreted format of min and max values. Note that this line of code does not produce any error or warning. The user (at least in my case) assumed min_value and max_value would be raised to float rather than ignoring format. I couldn't figure out why my input was being reduced from 170.4 to 170

The correct code works fine
`weight = st.number_input("Today's weight:", min_value=50.0, max_value=750.0, format="%4.1f")`

## Expected behavior:

A warning in both cases, not just one or the other. Maybe:
_Warning: NumberInput value below is integer, format %f lowered to match integer._

## Actual behavior:

No warning produced, seems like there should be. 
Sorry, already explained in the Steps to Reproduce section

## Is this a regression?

No (not that I know of)

# Debug info

- Streamlit version: (get it with `$ streamlit version`) 0.64.0
- Python version: (get it with `$ python --version`) 3.7.7
- Using Conda
- OS version: Windows 10 64bit
- Browser version: Chrome Version 84.0.4147.105 (Official Build) (64-bit)

# Additional information




Discussion:
Hey @CheapSquier -- Thanks, I agree this is an annoyance we should clear up.  Thanks for the detailed report!

Some history: #930 and #1681 


Hi @saNed -- you're welcome to submit a PR!
Note: original warning is raised in https://github.com/streamlit/streamlit/blob/develop/lib/streamlit/elements/number_input.py#L83, so that would be a good place to introduce a new warning

Resolving patch:
diff --git a/lib/streamlit/elements/number_input.py b/lib/streamlit/elements/number_input.py
--- a/lib/streamlit/elements/number_input.py
+++ b/lib/streamlit/elements/number_input.py
@@ -55,7 +55,7 @@ def number_input(
         format : str or None
             A printf-style format string controlling how the interface should
             display numbers. Output must be purely numeric. This does not impact
-            the return value. Valid formatters: %d %e %f %g %i
+            the return value. Valid formatters: %d %e %f %g %i %u
         key : str
             An optional string to use as the unique key for the widget.
             If this is omitted, a key will be generated for the widget
@@ -91,14 +91,20 @@ def number_input(
             if format is None:
                 format = "%d" if int_value else "%0.2f"
 
+            # Warn user if they format an int type as a float or vice versa.
             if format in ["%d", "%u", "%i"] and float_value:
-                # Warn user to check if displaying float as int was really intended.
                 import streamlit as st
 
                 st.warning(
-                    "Warning: NumberInput value below is float, but format {} displays as integer.".format(
-                        format
-                    )
+                    "Warning: NumberInput value below has type float,"
+                    f" but format {format} displays as integer."
+                )
+            elif format[-1] == "f" and int_value:
+                import streamlit as st
+
+                st.warning(
+                    "Warning: NumberInput value below has type int so is"
+                    f" displayed as int despite format string {format}."
                 )
 
             if step is None:


Test patch:
diff --git a/lib/tests/streamlit/number_input_test.py b/lib/tests/streamlit/number_input_test.py
--- a/lib/tests/streamlit/number_input_test.py
+++ b/lib/tests/streamlit/number_input_test.py
@@ -19,6 +19,7 @@
 import streamlit as st
 from streamlit.errors import StreamlitAPIException
 from streamlit.js_number import JSNumber
+from streamlit.proto.Alert_pb2 import Alert as AlertProto
 from streamlit.proto.NumberInput_pb2 import NumberInput
 from tests import testutil
 
@@ -35,7 +36,7 @@ def test_data_type(self):
         st.number_input("Label", value=0.5)
         c = self.get_delta_from_queue().new_element.number_input
         self.assertEqual(NumberInput.FLOAT, c.data_type)
-        
+
     def test_min_value_zero_sets_default_value(self):
         st.number_input("Label", 0, 10)
         c = self.get_delta_from_queue().new_element.number_input
@@ -124,6 +125,26 @@ def test_accept_valid_formats(self):
             c = self.get_delta_from_queue().new_element.number_input
             self.assertEqual(c.format, "%" + char)
 
+    def test_warns_on_float_type_with_int_format(self):
+        st.number_input("the label", value=5.0, format="%d")
+
+        c = self.get_delta_from_queue(-2).new_element.alert
+        self.assertEqual(c.format, AlertProto.WARNING)
+        self.assertEqual(
+            c.body,
+            "Warning: NumberInput value below has type float, but format %d displays as integer.",
+        )
+
+    def test_warns_on_int_type_with_float_format(self):
+        st.number_input("the label", value=5, format="%0.2f")
+
+        c = self.get_delta_from_queue(-2).new_element.alert
+        self.assertEqual(c.format, AlertProto.WARNING)
+        self.assertEqual(
+            c.body,
+            "Warning: NumberInput value below has type int so is displayed as int despite format string %0.2f.",
+        )
+
     def test_error_on_unsupported_formatters(self):
         UNSUPPORTED = "pAn"
         for char in UNSUPPORTED: