streamlit-nightly 1.36.1.dev20240702__py2.py3-none-any.whl → 1.36.1.dev20240704__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- streamlit/commands/navigation.py +1 -1
- streamlit/components/v1/component_arrow.py +16 -11
- streamlit/components/v1/custom_component.py +2 -1
- streamlit/dataframe_util.py +884 -0
- streamlit/delta_generator.py +6 -4
- streamlit/elements/arrow.py +26 -45
- streamlit/elements/lib/built_in_chart_utils.py +78 -19
- streamlit/elements/lib/column_config_utils.py +1 -1
- streamlit/elements/lib/pandas_styler_utils.py +4 -2
- streamlit/elements/lib/policies.py +60 -8
- streamlit/elements/lib/utils.py +100 -10
- streamlit/elements/map.py +4 -15
- streamlit/elements/metric.py +5 -2
- streamlit/elements/plotly_chart.py +11 -12
- streamlit/elements/vega_charts.py +19 -31
- streamlit/elements/widgets/button.py +17 -15
- streamlit/elements/widgets/camera_input.py +15 -10
- streamlit/elements/widgets/chat.py +9 -11
- streamlit/elements/widgets/checkbox.py +13 -11
- streamlit/elements/widgets/color_picker.py +14 -10
- streamlit/elements/widgets/data_editor.py +18 -19
- streamlit/elements/widgets/file_uploader.py +15 -10
- streamlit/elements/widgets/multiselect.py +13 -15
- streamlit/elements/widgets/number_input.py +13 -11
- streamlit/elements/widgets/radio.py +13 -15
- streamlit/elements/widgets/select_slider.py +13 -13
- streamlit/elements/widgets/selectbox.py +13 -15
- streamlit/elements/widgets/slider.py +14 -10
- streamlit/elements/widgets/text_widgets.py +21 -17
- streamlit/elements/widgets/time_widgets.py +18 -16
- streamlit/elements/write.py +7 -15
- streamlit/runtime/caching/cache_utils.py +2 -5
- streamlit/runtime/state/common.py +51 -2
- streamlit/runtime/state/session_state.py +2 -1
- streamlit/runtime/state/session_state_proxy.py +1 -1
- streamlit/runtime/state/widgets.py +1 -1
- streamlit/static/asset-manifest.json +2 -2
- streamlit/static/index.html +1 -1
- streamlit/static/static/js/{main.e2ab315a.js → main.28e3c6e9.js} +2 -2
- streamlit/testing/v1/element_tree.py +3 -3
- streamlit/type_util.py +0 -1069
- {streamlit_nightly-1.36.1.dev20240702.dist-info → streamlit_nightly-1.36.1.dev20240704.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.36.1.dev20240702.dist-info → streamlit_nightly-1.36.1.dev20240704.dist-info}/RECORD +48 -47
- /streamlit/static/static/js/{main.e2ab315a.js.LICENSE.txt → main.28e3c6e9.js.LICENSE.txt} +0 -0
- {streamlit_nightly-1.36.1.dev20240702.data → streamlit_nightly-1.36.1.dev20240704.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.36.1.dev20240702.dist-info → streamlit_nightly-1.36.1.dev20240704.dist-info}/WHEEL +0 -0
- {streamlit_nightly-1.36.1.dev20240702.dist-info → streamlit_nightly-1.36.1.dev20240704.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.36.1.dev20240702.dist-info → streamlit_nightly-1.36.1.dev20240704.dist-info}/top_level.txt +0 -0
streamlit/elements/map.py
CHANGED
@@ -19,12 +19,10 @@ from __future__ import annotations
|
|
19
19
|
import copy
|
20
20
|
import hashlib
|
21
21
|
import json
|
22
|
-
from typing import TYPE_CHECKING, Any, Collection,
|
23
|
-
|
24
|
-
from typing_extensions import TypeAlias
|
22
|
+
from typing import TYPE_CHECKING, Any, Collection, Final, cast
|
25
23
|
|
26
24
|
import streamlit.elements.deck_gl_json_chart as deck_gl_json_chart
|
27
|
-
from streamlit import config,
|
25
|
+
from streamlit import config, dataframe_util
|
28
26
|
from streamlit.color_util import Color, IntColorTuple, is_color_like, to_int_color_tuple
|
29
27
|
from streamlit.errors import StreamlitAPIException
|
30
28
|
from streamlit.proto.DeckGlJsonChart_pb2 import DeckGlJsonChart as DeckGlJsonChartProto
|
@@ -33,19 +31,10 @@ from streamlit.util import HASHLIB_KWARGS
|
|
33
31
|
|
34
32
|
if TYPE_CHECKING:
|
35
33
|
from pandas import DataFrame
|
36
|
-
from pandas.io.formats.style import Styler
|
37
34
|
|
35
|
+
from streamlit.dataframe_util import Data
|
38
36
|
from streamlit.delta_generator import DeltaGenerator
|
39
37
|
|
40
|
-
|
41
|
-
Data: TypeAlias = Union[
|
42
|
-
"DataFrame",
|
43
|
-
"Styler",
|
44
|
-
Iterable[Any],
|
45
|
-
Dict[Any, Any],
|
46
|
-
None,
|
47
|
-
]
|
48
|
-
|
49
38
|
# Map used as the basis for st.map.
|
50
39
|
_DEFAULT_MAP: Final[dict[str, Any]] = dict(deck_gl_json_chart.EMPTY_MAP)
|
51
40
|
|
@@ -263,7 +252,7 @@ def to_deckgl_json(
|
|
263
252
|
if hasattr(data, "empty") and data.empty:
|
264
253
|
return json.dumps(_DEFAULT_MAP)
|
265
254
|
|
266
|
-
df =
|
255
|
+
df = dataframe_util.convert_anything_to_pandas_df(data)
|
267
256
|
|
268
257
|
lat_col_name = _get_lat_or_lon_col_name(df, "latitude", lat, _DEFAULT_LAT_COL_NAMES)
|
269
258
|
lon_col_name = _get_lat_or_lon_col_name(
|
streamlit/elements/metric.py
CHANGED
@@ -20,12 +20,15 @@ from typing import TYPE_CHECKING, Literal, Union, cast
|
|
20
20
|
|
21
21
|
from typing_extensions import TypeAlias
|
22
22
|
|
23
|
-
from streamlit.elements.lib.
|
23
|
+
from streamlit.elements.lib.policies import maybe_raise_label_warnings
|
24
|
+
from streamlit.elements.lib.utils import (
|
25
|
+
LabelVisibility,
|
26
|
+
get_label_visibility_proto_value,
|
27
|
+
)
|
24
28
|
from streamlit.errors import StreamlitAPIException
|
25
29
|
from streamlit.proto.Metric_pb2 import Metric as MetricProto
|
26
30
|
from streamlit.runtime.metrics_util import gather_metrics
|
27
31
|
from streamlit.string_util import clean_text
|
28
|
-
from streamlit.type_util import LabelVisibility, maybe_raise_label_warnings
|
29
32
|
|
30
33
|
if TYPE_CHECKING:
|
31
34
|
import numpy as np
|
@@ -38,22 +38,17 @@ from streamlit import type_util
|
|
38
38
|
from streamlit.deprecation_util import show_deprecation_warning
|
39
39
|
from streamlit.elements.form import current_form_id
|
40
40
|
from streamlit.elements.lib.event_utils import AttributeDictionary
|
41
|
-
from streamlit.elements.lib.policies import
|
42
|
-
check_cache_replay_rules,
|
43
|
-
check_callback_rules,
|
44
|
-
check_fragment_path_policy,
|
45
|
-
check_session_state_rules,
|
46
|
-
)
|
41
|
+
from streamlit.elements.lib.policies import check_widget_policies
|
47
42
|
from streamlit.elements.lib.streamlit_plotly_theme import (
|
48
43
|
configure_streamlit_plotly_theme,
|
49
44
|
)
|
45
|
+
from streamlit.elements.lib.utils import Key, to_key
|
50
46
|
from streamlit.errors import StreamlitAPIException
|
51
47
|
from streamlit.proto.PlotlyChart_pb2 import PlotlyChart as PlotlyChartProto
|
52
48
|
from streamlit.runtime.metrics_util import gather_metrics
|
53
49
|
from streamlit.runtime.scriptrunner import get_script_run_ctx
|
54
50
|
from streamlit.runtime.state import WidgetCallback, register_widget
|
55
51
|
from streamlit.runtime.state.common import compute_widget_id
|
56
|
-
from streamlit.type_util import Key, to_key
|
57
52
|
|
58
53
|
if TYPE_CHECKING:
|
59
54
|
import matplotlib
|
@@ -467,11 +462,15 @@ class PlotlyMixin:
|
|
467
462
|
if is_selection_activated:
|
468
463
|
# Run some checks that are only relevant when selections are activated
|
469
464
|
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
465
|
+
is_callback = callable(on_select)
|
466
|
+
check_widget_policies(
|
467
|
+
self.dg,
|
468
|
+
key,
|
469
|
+
on_change=cast(WidgetCallback, on_select) if is_callback else None,
|
470
|
+
default_value=None,
|
471
|
+
writes_allowed=False,
|
472
|
+
enable_check_callback_rules=is_callback,
|
473
|
+
)
|
475
474
|
|
476
475
|
if type_util.is_type(figure_or_data, "matplotlib.figure.Figure"):
|
477
476
|
# Convert matplotlib figure to plotly figure:
|
@@ -36,37 +36,32 @@ from typing import (
|
|
36
36
|
from typing_extensions import TypeAlias
|
37
37
|
|
38
38
|
import streamlit.elements.lib.dicttools as dicttools
|
39
|
-
from streamlit import type_util
|
39
|
+
from streamlit import dataframe_util, type_util
|
40
40
|
from streamlit.elements.lib.built_in_chart_utils import (
|
41
41
|
AddRowsMetadata,
|
42
|
+
ChartStackType,
|
42
43
|
ChartType,
|
43
44
|
generate_chart,
|
44
45
|
)
|
45
46
|
from streamlit.elements.lib.event_utils import AttributeDictionary
|
46
|
-
from streamlit.elements.lib.policies import
|
47
|
-
|
48
|
-
check_callback_rules,
|
49
|
-
check_fragment_path_policy,
|
50
|
-
check_session_state_rules,
|
51
|
-
)
|
47
|
+
from streamlit.elements.lib.policies import check_widget_policies
|
48
|
+
from streamlit.elements.lib.utils import Key, to_key
|
52
49
|
from streamlit.errors import StreamlitAPIException
|
53
50
|
from streamlit.proto.ArrowVegaLiteChart_pb2 import (
|
54
51
|
ArrowVegaLiteChart as ArrowVegaLiteChartProto,
|
55
52
|
)
|
56
53
|
from streamlit.runtime.metrics_util import gather_metrics
|
57
54
|
from streamlit.runtime.scriptrunner import get_script_run_ctx
|
58
|
-
from streamlit.runtime.state import register_widget
|
55
|
+
from streamlit.runtime.state import WidgetCallback, register_widget
|
59
56
|
from streamlit.runtime.state.common import compute_widget_id
|
60
|
-
from streamlit.type_util import ChartStackType, Key, to_key
|
61
57
|
from streamlit.util import HASHLIB_KWARGS
|
62
58
|
|
63
59
|
if TYPE_CHECKING:
|
64
60
|
import altair as alt
|
65
61
|
|
66
62
|
from streamlit.color_util import Color
|
63
|
+
from streamlit.dataframe_util import Data
|
67
64
|
from streamlit.delta_generator import DeltaGenerator
|
68
|
-
from streamlit.elements.arrow import Data
|
69
|
-
from streamlit.runtime.state import WidgetCallback
|
70
65
|
|
71
66
|
# See https://vega.github.io/vega-lite/docs/encoding.html
|
72
67
|
_CHANNELS: Final = {
|
@@ -274,17 +269,6 @@ def _prepare_vega_lite_spec(
|
|
274
269
|
return spec
|
275
270
|
|
276
271
|
|
277
|
-
def _serialize_data(data: Any) -> bytes:
|
278
|
-
"""Serialize the any type of data structure to Arrow IPC format (bytes)."""
|
279
|
-
import pyarrow as pa
|
280
|
-
|
281
|
-
if isinstance(data, pa.Table):
|
282
|
-
return type_util.pyarrow_table_to_bytes(data)
|
283
|
-
|
284
|
-
df = type_util.convert_anything_to_df(data)
|
285
|
-
return type_util.data_frame_to_bytes(df)
|
286
|
-
|
287
|
-
|
288
272
|
def _marshall_chart_data(
|
289
273
|
proto: ArrowVegaLiteChartProto,
|
290
274
|
spec: VegaLiteSpec,
|
@@ -307,11 +291,11 @@ def _marshall_chart_data(
|
|
307
291
|
# We just need to pass the data information into the correct proto fields.
|
308
292
|
|
309
293
|
# TODO(lukasmasuch): Are there any other cases where we need to serialize the data
|
310
|
-
#
|
294
|
+
# or can we remove the convert_anything_to_arrow_bytes here?
|
311
295
|
dataset.data.data = (
|
312
296
|
dataset_data
|
313
297
|
if isinstance(dataset_data, bytes)
|
314
|
-
else
|
298
|
+
else dataframe_util.convert_anything_to_arrow_bytes(dataset_data)
|
315
299
|
)
|
316
300
|
del spec["datasets"]
|
317
301
|
|
@@ -332,7 +316,7 @@ def _marshall_chart_data(
|
|
332
316
|
del spec["data"]
|
333
317
|
|
334
318
|
if data is not None:
|
335
|
-
proto.data.data =
|
319
|
+
proto.data.data = dataframe_util.convert_anything_to_arrow_bytes(data)
|
336
320
|
|
337
321
|
|
338
322
|
def _convert_altair_to_vega_lite_spec(altair_chart: alt.Chart) -> VegaLiteSpec:
|
@@ -354,7 +338,7 @@ def _convert_altair_to_vega_lite_spec(altair_chart: alt.Chart) -> VegaLiteSpec:
|
|
354
338
|
"""
|
355
339
|
# Already serialize the data to be able to create a stable
|
356
340
|
# dataset name:
|
357
|
-
data_bytes =
|
341
|
+
data_bytes = dataframe_util.convert_anything_to_arrow_bytes(data)
|
358
342
|
# Use the md5 hash of the data as the name:
|
359
343
|
h = hashlib.new("md5", **HASHLIB_KWARGS)
|
360
344
|
h.update(str(data_bytes).encode("utf-8"))
|
@@ -1787,11 +1771,15 @@ class VegaChartsMixin:
|
|
1787
1771
|
if is_selection_activated:
|
1788
1772
|
# Run some checks that are only relevant when selections are activated
|
1789
1773
|
|
1790
|
-
|
1791
|
-
|
1792
|
-
|
1793
|
-
|
1794
|
-
|
1774
|
+
is_callback = callable(on_select)
|
1775
|
+
check_widget_policies(
|
1776
|
+
self.dg,
|
1777
|
+
key,
|
1778
|
+
on_change=cast(WidgetCallback, on_select) if is_callback else None,
|
1779
|
+
default_value=None,
|
1780
|
+
writes_allowed=False,
|
1781
|
+
enable_check_callback_rules=is_callback,
|
1782
|
+
)
|
1795
1783
|
|
1796
1784
|
# Support passing data inside spec['datasets'] and spec['data'].
|
1797
1785
|
# (The data gets pulled out of the spec dict later on.)
|
@@ -24,12 +24,8 @@ from typing_extensions import TypeAlias
|
|
24
24
|
|
25
25
|
from streamlit import runtime
|
26
26
|
from streamlit.elements.form import current_form_id, is_in_form
|
27
|
-
from streamlit.elements.lib.policies import
|
28
|
-
|
29
|
-
check_callback_rules,
|
30
|
-
check_fragment_path_policy,
|
31
|
-
check_session_state_rules,
|
32
|
-
)
|
27
|
+
from streamlit.elements.lib.policies import check_widget_policies
|
28
|
+
from streamlit.elements.lib.utils import Key, to_key
|
33
29
|
from streamlit.errors import StreamlitAPIException
|
34
30
|
from streamlit.file_util import get_main_script_directory, normalize_path_join
|
35
31
|
from streamlit.navigation.page import StreamlitPage
|
@@ -47,7 +43,6 @@ from streamlit.runtime.state import (
|
|
47
43
|
)
|
48
44
|
from streamlit.runtime.state.common import compute_widget_id, save_for_app_testing
|
49
45
|
from streamlit.string_util import validate_icon_or_emoji
|
50
|
-
from streamlit.type_util import Key, to_key
|
51
46
|
from streamlit.url_util import is_url
|
52
47
|
|
53
48
|
if TYPE_CHECKING:
|
@@ -600,9 +595,13 @@ class ButtonMixin:
|
|
600
595
|
) -> bool:
|
601
596
|
key = to_key(key)
|
602
597
|
|
603
|
-
|
604
|
-
|
605
|
-
|
598
|
+
check_widget_policies(
|
599
|
+
self.dg,
|
600
|
+
key,
|
601
|
+
on_click,
|
602
|
+
default_value=None,
|
603
|
+
writes_allowed=False,
|
604
|
+
)
|
606
605
|
|
607
606
|
id = compute_widget_id(
|
608
607
|
"download_button",
|
@@ -764,11 +763,14 @@ class ButtonMixin:
|
|
764
763
|
) -> bool:
|
765
764
|
key = to_key(key)
|
766
765
|
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
766
|
+
check_widget_policies(
|
767
|
+
self.dg,
|
768
|
+
key,
|
769
|
+
on_click,
|
770
|
+
default_value=None,
|
771
|
+
writes_allowed=False,
|
772
|
+
enable_check_callback_rules=not is_form_submitter,
|
773
|
+
)
|
772
774
|
|
773
775
|
id = compute_widget_id(
|
774
776
|
"button",
|
@@ -22,12 +22,15 @@ from typing_extensions import TypeAlias
|
|
22
22
|
|
23
23
|
from streamlit.elements.form import current_form_id
|
24
24
|
from streamlit.elements.lib.policies import (
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
check_widget_policies,
|
26
|
+
maybe_raise_label_warnings,
|
27
|
+
)
|
28
|
+
from streamlit.elements.lib.utils import (
|
29
|
+
Key,
|
30
|
+
LabelVisibility,
|
31
|
+
get_label_visibility_proto_value,
|
32
|
+
to_key,
|
29
33
|
)
|
30
|
-
from streamlit.elements.lib.utils import get_label_visibility_proto_value
|
31
34
|
from streamlit.elements.widgets.file_uploader import _get_upload_files
|
32
35
|
from streamlit.proto.CameraInput_pb2 import CameraInput as CameraInputProto
|
33
36
|
from streamlit.proto.Common_pb2 import FileUploaderState as FileUploaderStateProto
|
@@ -42,7 +45,6 @@ from streamlit.runtime.state import (
|
|
42
45
|
)
|
43
46
|
from streamlit.runtime.state.common import compute_widget_id
|
44
47
|
from streamlit.runtime.uploaded_file_manager import DeletedFile, UploadedFile
|
45
|
-
from streamlit.type_util import Key, LabelVisibility, maybe_raise_label_warnings, to_key
|
46
48
|
|
47
49
|
if TYPE_CHECKING:
|
48
50
|
from streamlit.delta_generator import DeltaGenerator
|
@@ -201,10 +203,13 @@ class CameraInputMixin:
|
|
201
203
|
) -> UploadedFile | None:
|
202
204
|
key = to_key(key)
|
203
205
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
206
|
+
check_widget_policies(
|
207
|
+
self.dg,
|
208
|
+
key,
|
209
|
+
on_change,
|
210
|
+
default_value=None,
|
211
|
+
writes_allowed=False,
|
212
|
+
)
|
208
213
|
maybe_raise_label_warnings(label, label_visibility)
|
209
214
|
|
210
215
|
id = compute_widget_id(
|
@@ -21,12 +21,8 @@ from typing import TYPE_CHECKING, Literal, cast
|
|
21
21
|
from streamlit import runtime
|
22
22
|
from streamlit.elements.form import is_in_form
|
23
23
|
from streamlit.elements.image import AtomicImage, WidthBehaviour, image_to_url
|
24
|
-
from streamlit.elements.lib.policies import
|
25
|
-
|
26
|
-
check_callback_rules,
|
27
|
-
check_fragment_path_policy,
|
28
|
-
check_session_state_rules,
|
29
|
-
)
|
24
|
+
from streamlit.elements.lib.policies import check_widget_policies
|
25
|
+
from streamlit.elements.lib.utils import Key, to_key
|
30
26
|
from streamlit.errors import StreamlitAPIException
|
31
27
|
from streamlit.proto.Block_pb2 import Block as BlockProto
|
32
28
|
from streamlit.proto.ChatInput_pb2 import ChatInput as ChatInputProto
|
@@ -42,7 +38,6 @@ from streamlit.runtime.state import (
|
|
42
38
|
)
|
43
39
|
from streamlit.runtime.state.common import compute_widget_id, save_for_app_testing
|
44
40
|
from streamlit.string_util import is_emoji, validate_material_icon
|
45
|
-
from streamlit.type_util import Key, to_key
|
46
41
|
|
47
42
|
if TYPE_CHECKING:
|
48
43
|
from streamlit.delta_generator import DeltaGenerator
|
@@ -317,10 +312,13 @@ class ChatMixin:
|
|
317
312
|
default = ""
|
318
313
|
key = to_key(key)
|
319
314
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
315
|
+
check_widget_policies(
|
316
|
+
self.dg,
|
317
|
+
key,
|
318
|
+
on_submit,
|
319
|
+
default_value=default,
|
320
|
+
writes_allowed=False,
|
321
|
+
)
|
324
322
|
|
325
323
|
ctx = get_script_run_ctx()
|
326
324
|
id = compute_widget_id(
|
@@ -20,12 +20,15 @@ from typing import TYPE_CHECKING, cast
|
|
20
20
|
|
21
21
|
from streamlit.elements.form import current_form_id
|
22
22
|
from streamlit.elements.lib.policies import (
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
check_widget_policies,
|
24
|
+
maybe_raise_label_warnings,
|
25
|
+
)
|
26
|
+
from streamlit.elements.lib.utils import (
|
27
|
+
Key,
|
28
|
+
LabelVisibility,
|
29
|
+
get_label_visibility_proto_value,
|
30
|
+
to_key,
|
27
31
|
)
|
28
|
-
from streamlit.elements.lib.utils import get_label_visibility_proto_value
|
29
32
|
from streamlit.proto.Checkbox_pb2 import Checkbox as CheckboxProto
|
30
33
|
from streamlit.runtime.metrics_util import gather_metrics
|
31
34
|
from streamlit.runtime.scriptrunner import ScriptRunContext, get_script_run_ctx
|
@@ -36,7 +39,6 @@ from streamlit.runtime.state import (
|
|
36
39
|
register_widget,
|
37
40
|
)
|
38
41
|
from streamlit.runtime.state.common import compute_widget_id
|
39
|
-
from streamlit.type_util import Key, LabelVisibility, maybe_raise_label_warnings, to_key
|
40
42
|
|
41
43
|
if TYPE_CHECKING:
|
42
44
|
from streamlit.delta_generator import DeltaGenerator
|
@@ -283,11 +285,11 @@ class CheckboxMixin:
|
|
283
285
|
) -> bool:
|
284
286
|
key = to_key(key)
|
285
287
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
default_value=None if value is False else value,
|
288
|
+
check_widget_policies(
|
289
|
+
self.dg,
|
290
|
+
key,
|
291
|
+
on_change,
|
292
|
+
default_value=None if value is False else value,
|
291
293
|
)
|
292
294
|
maybe_raise_label_warnings(label, label_visibility)
|
293
295
|
|
@@ -21,12 +21,15 @@ from typing import TYPE_CHECKING, cast
|
|
21
21
|
|
22
22
|
from streamlit.elements.form import current_form_id
|
23
23
|
from streamlit.elements.lib.policies import (
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
check_widget_policies,
|
25
|
+
maybe_raise_label_warnings,
|
26
|
+
)
|
27
|
+
from streamlit.elements.lib.utils import (
|
28
|
+
Key,
|
29
|
+
LabelVisibility,
|
30
|
+
get_label_visibility_proto_value,
|
31
|
+
to_key,
|
28
32
|
)
|
29
|
-
from streamlit.elements.lib.utils import get_label_visibility_proto_value
|
30
33
|
from streamlit.errors import StreamlitAPIException
|
31
34
|
from streamlit.proto.ColorPicker_pb2 import ColorPicker as ColorPickerProto
|
32
35
|
from streamlit.runtime.metrics_util import gather_metrics
|
@@ -38,7 +41,6 @@ from streamlit.runtime.state import (
|
|
38
41
|
register_widget,
|
39
42
|
)
|
40
43
|
from streamlit.runtime.state.common import compute_widget_id
|
41
|
-
from streamlit.type_util import Key, LabelVisibility, maybe_raise_label_warnings, to_key
|
42
44
|
|
43
45
|
if TYPE_CHECKING:
|
44
46
|
from streamlit.delta_generator import DeltaGenerator
|
@@ -177,10 +179,12 @@ class ColorPickerMixin:
|
|
177
179
|
) -> str:
|
178
180
|
key = to_key(key)
|
179
181
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
182
|
+
check_widget_policies(
|
183
|
+
self.dg,
|
184
|
+
key,
|
185
|
+
on_change,
|
186
|
+
default_value=value,
|
187
|
+
)
|
184
188
|
maybe_raise_label_warnings(label, label_visibility)
|
185
189
|
|
186
190
|
id = compute_widget_id(
|
@@ -37,8 +37,8 @@ from typing import (
|
|
37
37
|
|
38
38
|
from typing_extensions import TypeAlias
|
39
39
|
|
40
|
+
from streamlit import dataframe_util
|
40
41
|
from streamlit import logger as _logger
|
41
|
-
from streamlit import type_util
|
42
42
|
from streamlit.elements.form import current_form_id
|
43
43
|
from streamlit.elements.lib.column_config_utils import (
|
44
44
|
INDEX_IDENTIFIER,
|
@@ -54,12 +54,8 @@ from streamlit.elements.lib.column_config_utils import (
|
|
54
54
|
update_column_config,
|
55
55
|
)
|
56
56
|
from streamlit.elements.lib.pandas_styler_utils import marshall_styler
|
57
|
-
from streamlit.elements.lib.policies import
|
58
|
-
|
59
|
-
check_callback_rules,
|
60
|
-
check_fragment_path_policy,
|
61
|
-
check_session_state_rules,
|
62
|
-
)
|
57
|
+
from streamlit.elements.lib.policies import check_widget_policies
|
58
|
+
from streamlit.elements.lib.utils import Key, to_key
|
63
59
|
from streamlit.errors import StreamlitAPIException
|
64
60
|
from streamlit.proto.Arrow_pb2 import Arrow as ArrowProto
|
65
61
|
from streamlit.runtime.metrics_util import gather_metrics
|
@@ -71,7 +67,7 @@ from streamlit.runtime.state import (
|
|
71
67
|
register_widget,
|
72
68
|
)
|
73
69
|
from streamlit.runtime.state.common import compute_widget_id
|
74
|
-
from streamlit.type_util import
|
70
|
+
from streamlit.type_util import is_type
|
75
71
|
from streamlit.util import calc_md5
|
76
72
|
|
77
73
|
if TYPE_CHECKING:
|
@@ -89,7 +85,7 @@ _LOGGER: Final = _logger.get_logger(__name__)
|
|
89
85
|
EditableData = TypeVar(
|
90
86
|
"EditableData",
|
91
87
|
bound=Union[
|
92
|
-
DataFrameGenericAlias[Any], # covers DataFrame and Series
|
88
|
+
dataframe_util.DataFrameGenericAlias[Any], # covers DataFrame and Series
|
93
89
|
Tuple[Any],
|
94
90
|
List[Any],
|
95
91
|
Set[Any],
|
@@ -785,18 +781,21 @@ class DataEditorMixin:
|
|
785
781
|
|
786
782
|
key = to_key(key)
|
787
783
|
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
784
|
+
check_widget_policies(
|
785
|
+
self.dg,
|
786
|
+
key,
|
787
|
+
on_change,
|
788
|
+
default_value=None,
|
789
|
+
writes_allowed=False,
|
790
|
+
)
|
792
791
|
|
793
792
|
if column_order is not None:
|
794
793
|
column_order = list(column_order)
|
795
794
|
|
796
795
|
column_config_mapping: ColumnConfigMapping = {}
|
797
796
|
|
798
|
-
data_format =
|
799
|
-
if data_format == DataFormat.UNKNOWN:
|
797
|
+
data_format = dataframe_util.determine_data_format(data)
|
798
|
+
if data_format == dataframe_util.DataFormat.UNKNOWN:
|
800
799
|
raise StreamlitAPIException(
|
801
800
|
f"The data type ({type(data).__name__}) or format is not supported by the data editor. "
|
802
801
|
"Please convert your data into a Pandas Dataframe or another supported data format."
|
@@ -804,7 +803,7 @@ class DataEditorMixin:
|
|
804
803
|
|
805
804
|
# The dataframe should always be a copy of the original data
|
806
805
|
# since we will apply edits directly to it.
|
807
|
-
data_df =
|
806
|
+
data_df = dataframe_util.convert_anything_to_pandas_df(data, ensure_copy=True)
|
808
807
|
|
809
808
|
# Check if the index is supported.
|
810
809
|
if not _is_supported_index(data_df.index):
|
@@ -855,7 +854,7 @@ class DataEditorMixin:
|
|
855
854
|
# Throws an exception if any of the configured types are incompatible.
|
856
855
|
_check_type_compatibilities(data_df, column_config_mapping, dataframe_schema)
|
857
856
|
|
858
|
-
arrow_bytes =
|
857
|
+
arrow_bytes = dataframe_util.convert_arrow_table_to_arrow_bytes(arrow_table)
|
859
858
|
|
860
859
|
# We want to do this as early as possible to avoid introducing nondeterminism,
|
861
860
|
# but it isn't clear how much processing is needed to have the data in a
|
@@ -902,7 +901,7 @@ class DataEditorMixin:
|
|
902
901
|
|
903
902
|
proto.form_id = current_form_id(self.dg)
|
904
903
|
|
905
|
-
if
|
904
|
+
if dataframe_util.is_pandas_styler(data):
|
906
905
|
# Pandas styler will only work for non-editable/disabled columns.
|
907
906
|
# Get first 10 chars of md5 hash of the key or delta path as styler uuid
|
908
907
|
# and set it as styler uuid.
|
@@ -936,7 +935,7 @@ class DataEditorMixin:
|
|
936
935
|
|
937
936
|
_apply_dataframe_edits(data_df, widget_state.value, dataframe_schema)
|
938
937
|
self.dg._enqueue("arrow_data_frame", proto)
|
939
|
-
return
|
938
|
+
return dataframe_util.convert_pandas_df_to_data_format(data_df, data_format)
|
940
939
|
|
941
940
|
@property
|
942
941
|
def dg(self) -> DeltaGenerator:
|
@@ -23,12 +23,15 @@ from typing_extensions import TypeAlias
|
|
23
23
|
from streamlit import config
|
24
24
|
from streamlit.elements.form import current_form_id
|
25
25
|
from streamlit.elements.lib.policies import (
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
check_widget_policies,
|
27
|
+
maybe_raise_label_warnings,
|
28
|
+
)
|
29
|
+
from streamlit.elements.lib.utils import (
|
30
|
+
Key,
|
31
|
+
LabelVisibility,
|
32
|
+
get_label_visibility_proto_value,
|
33
|
+
to_key,
|
30
34
|
)
|
31
|
-
from streamlit.elements.lib.utils import get_label_visibility_proto_value
|
32
35
|
from streamlit.proto.Common_pb2 import FileUploaderState as FileUploaderStateProto
|
33
36
|
from streamlit.proto.Common_pb2 import UploadedFileInfo as UploadedFileInfoProto
|
34
37
|
from streamlit.proto.FileUploader_pb2 import FileUploader as FileUploaderProto
|
@@ -42,7 +45,6 @@ from streamlit.runtime.state import (
|
|
42
45
|
)
|
43
46
|
from streamlit.runtime.state.common import compute_widget_id
|
44
47
|
from streamlit.runtime.uploaded_file_manager import DeletedFile, UploadedFile
|
45
|
-
from streamlit.type_util import Key, LabelVisibility, maybe_raise_label_warnings, to_key
|
46
48
|
|
47
49
|
if TYPE_CHECKING:
|
48
50
|
from streamlit.delta_generator import DeltaGenerator
|
@@ -400,10 +402,13 @@ class FileUploaderMixin:
|
|
400
402
|
) -> UploadedFile | list[UploadedFile] | None:
|
401
403
|
key = to_key(key)
|
402
404
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
405
|
+
check_widget_policies(
|
406
|
+
self.dg,
|
407
|
+
key,
|
408
|
+
on_change,
|
409
|
+
default_value=None,
|
410
|
+
writes_allowed=False,
|
411
|
+
)
|
407
412
|
maybe_raise_label_warnings(label, label_visibility)
|
408
413
|
|
409
414
|
id = compute_widget_id(
|
@@ -18,16 +18,18 @@ from dataclasses import dataclass
|
|
18
18
|
from textwrap import dedent
|
19
19
|
from typing import TYPE_CHECKING, Any, Callable, Generic, Sequence, cast, overload
|
20
20
|
|
21
|
+
from streamlit.dataframe_util import OptionSequence, convert_anything_to_sequence
|
21
22
|
from streamlit.elements.form import current_form_id
|
22
23
|
from streamlit.elements.lib.policies import (
|
23
|
-
|
24
|
-
|
25
|
-
check_fragment_path_policy,
|
26
|
-
check_session_state_rules,
|
24
|
+
check_widget_policies,
|
25
|
+
maybe_raise_label_warnings,
|
27
26
|
)
|
28
27
|
from streamlit.elements.lib.utils import (
|
28
|
+
Key,
|
29
|
+
LabelVisibility,
|
29
30
|
get_label_visibility_proto_value,
|
30
31
|
maybe_coerce_enum_sequence,
|
32
|
+
to_key,
|
31
33
|
)
|
32
34
|
from streamlit.errors import StreamlitAPIException
|
33
35
|
from streamlit.proto.MultiSelect_pb2 import MultiSelect as MultiSelectProto
|
@@ -41,16 +43,10 @@ from streamlit.runtime.state import (
|
|
41
43
|
)
|
42
44
|
from streamlit.runtime.state.common import compute_widget_id, save_for_app_testing
|
43
45
|
from streamlit.type_util import (
|
44
|
-
Key,
|
45
|
-
LabelVisibility,
|
46
|
-
OptionSequence,
|
47
46
|
T,
|
48
47
|
check_python_comparable,
|
49
|
-
ensure_indexable,
|
50
48
|
is_iterable,
|
51
49
|
is_type,
|
52
|
-
maybe_raise_label_warnings,
|
53
|
-
to_key,
|
54
50
|
)
|
55
51
|
|
56
52
|
if TYPE_CHECKING:
|
@@ -292,13 +288,15 @@ class MultiSelectMixin:
|
|
292
288
|
) -> list[T]:
|
293
289
|
key = to_key(key)
|
294
290
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
291
|
+
check_widget_policies(
|
292
|
+
self.dg,
|
293
|
+
key,
|
294
|
+
on_change,
|
295
|
+
default_value=default,
|
296
|
+
)
|
299
297
|
maybe_raise_label_warnings(label, label_visibility)
|
300
298
|
|
301
|
-
opt =
|
299
|
+
opt = convert_anything_to_sequence(options)
|
302
300
|
check_python_comparable(opt)
|
303
301
|
|
304
302
|
indices = _check_and_convert_to_indices(opt, default)
|