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

Upgrade streamlit to >=1.30 #7

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


install_requires = [
'streamlit>=1.12,<2'
'streamlit>=1.30,<2'
]

tests_require = ['pytest', 'pytest-mock', 'tox']
Expand Down
2 changes: 1 addition & 1 deletion streamlit_parameters/demos/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def main():
streamlit.write("## Debugging")

streamlit.write("#### Query String")
query_string: typing.Dict[str, str] = streamlit.experimental_get_query_params()
query_string: typing.Dict[str, str] = streamlit.query_params.get_all()
Copy link
Owner

Choose a reason for hiding this comment

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

I get the following error with this:

File "/home/zen/.cache/pypoetry/virtualenvs/streamlit-parameters-Wj2vk3Ob-py3.10/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
    result = func()
File "/home/zen/.cache/pypoetry/virtualenvs/streamlit-parameters-Wj2vk3Ob-py3.10/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 579, in code_to_exec
    exec(code, module.__dict__)
File "/workspaces/streamlit_parameters/streamlit_parameters/demos/parameters.py", line 236, in <module>
    main()
File "/workspaces/streamlit_parameters/streamlit_parameters/demos/parameters.py", line 217, in main
    query_string: typing.Dict[str, str] = streamlit.query_params.get_all()
File "/home/zen/.cache/pypoetry/virtualenvs/streamlit-parameters-Wj2vk3Ob-py3.10/lib/python3.10/site-packages/streamlit/runtime/metrics_util.py", line 410, in wrapped_func
    result = non_optional_func(*args, **kwargs)

However, streamlit.write(streamlit.query_params) works fine.

Copy link
Owner

Choose a reason for hiding this comment

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

Perhaps the api changed (only works for get_all on a single key now).

This misses repeated keys, but that's fine since we're only using it for debugging.

streamlit.write(query_string)

streamlit.write("#### Parameters")
Expand Down
4 changes: 2 additions & 2 deletions streamlit_parameters/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def set_url_fields():
for key, parameter in streamlit.session_state._parameters.items():
if Parameters.is_set_all() or parameter.touched:
values[key] = parameter.to_str(parameter.value)
streamlit.experimental_set_query_params(**values)
streamlit.query_params.from_dict(values)

@staticmethod
def _already_registered(key: str) -> bool:
Expand All @@ -505,4 +505,4 @@ def _fetch_url_field(key: str) -> str:
KeyError: if the field does not exist
"""
# TODO: raise error if multiple values in the query_string exist
return streamlit.experimental_get_query_params()[key][0] # always a list, get the first
return streamlit.query_params[key]
24 changes: 12 additions & 12 deletions tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def mock_session_state(mocker):
def mock_query_params(mocker):
"""Add a pytest fixture that returns a function that mocks query params."""
def func(key: str, value: str):
get_query_params = mocker.patch(
sut + ".streamlit.experimental_get_query_params"
mocker.patch.dict(
sut + ".streamlit.query_params",
{key: value}
)
get_query_params.return_value = {key: [value]}

return func

Expand Down Expand Up @@ -176,9 +176,9 @@ def test_register_string_parameter(
assert parameter.default == "G'day!"
assert parameter.value == "Hello"
assert repr(parameter) == "Parameter(default=G'day!,value=Hello,touched=True)"
set_query_params = mocker.patch(sut + ".streamlit.experimental_set_query_params")
set_query_params = mocker.patch(sut + ".streamlit.runtime.state.query_params_proxy.QueryParamsProxy.from_dict")
Parameters.set_url_fields()
set_query_params.assert_called_with(foo="Hello")
set_query_params.assert_called_with({"foo": "Hello"})


def test_register_string_parameter_not_in_url(
Expand Down Expand Up @@ -223,14 +223,14 @@ def test_register_string_list_parameter(
repr(parameter)
== "Parameter(default=['flying', 'spaghetti', 'monster'],value=['flying', 'spaghetti', 'monster'],touched=True)"
)
set_query_params = mocker.patch(sut + ".streamlit.experimental_set_query_params")
set_query_params = mocker.patch(sut + ".streamlit.runtime.state.query_params_proxy.QueryParamsProxy.from_dict")
Parameters.set_url_fields()
set_query_params.assert_called_with(foo="['flying', 'spaghetti', 'monster']")
set_query_params.assert_called_with({"foo": "['flying', 'spaghetti', 'monster']"})

# Now update value and make sure new value properly serialized in query params
parameters.foo.update(new_value=["Hello", "world"])
Parameters.set_url_fields()
set_query_params.assert_called_with(foo="['Hello', 'world']")
set_query_params.assert_called_with({"foo": "['Hello', 'world']"})


def test_register_string_list_parameter_not_in_url(
Expand Down Expand Up @@ -278,9 +278,9 @@ def test_register_date_parameter(
parameter = st.session_state._parameters["foo"]
assert parameter.default == datetime.date(2021, 11, 1)
assert parameter.value == datetime.date(2021, 11, 1)
set_query_params = mocker.patch(sut + ".streamlit.experimental_set_query_params")
set_query_params = mocker.patch(sut + ".streamlit.runtime.state.query_params_proxy.QueryParamsProxy.from_dict")
Parameters.set_url_fields()
set_query_params.assert_called_with(foo="2021-11-01")
set_query_params.assert_called_with({"foo": "2021-11-01"})


def test_register_date_parameter_not_in_url(
Expand All @@ -307,10 +307,10 @@ def test_register_date_range_parameter(
assert parameter.value == (datetime.date(2021, 11, 1), datetime.date(2021, 11, 3))

# Now update value and make sure new value properly serialized in query params
set_query_params = mocker.patch(sut + ".streamlit.experimental_set_query_params")
set_query_params = mocker.patch(sut + ".streamlit.runtime.state.query_params_proxy.QueryParamsProxy.from_dict")
parameters.foo.update(new_value=(datetime.date(2023, 11, 1), datetime.date(2023, 11, 3)))
Parameters.set_url_fields()
set_query_params.assert_called_with(foo='(2023-11-01,2023-11-03)')
set_query_params.assert_called_with({"foo": '(2023-11-01,2023-11-03)'})


def test_as_dict(
Expand Down
Loading