def test_st_legacy_table(self): """Test st._legacy_table.""" df = pd.DataFrame([[1, 2], [3, 4]], columns=["col1", "col2"]) st._legacy_table(df) el = self.get_delta_from_queue().new_element self.assertEqual(el.table.data.cols[0].int64s.data, [1, 3]) self.assertEqual(el.table.data.cols[1].int64s.data, [2, 4]) self.assertEqual(el.table.columns.plain_index.data.strings.data, ["col1", "col2"])
def _get_unnamed_data_methods(self): """DeltaGenerator methods that do not produce named datasets.""" return [ lambda df: st._legacy_dataframe(df), lambda df: st._legacy_table(df), lambda df: st._legacy_vega_lite_chart( df, {"mark": "line", "encoding": {"x": "a", "y": "b"}} ), # TODO: _legacy_line_chart, _legacy_bar_chart, etc. ]
else: # from .apply(axis=None) is_max = data == data.max().max() return pd.DataFrame(np.where(is_max, attr, ""), index=data.index, columns=data.columns) # Create a table to be styled in various ways np.random.seed(24) df = pd.DataFrame({"A": np.linspace(1, 5, 5)}) df = pd.concat( [df, pd.DataFrame(np.random.randn(5, 4), columns=list("BCDE"))], axis=1) df.iloc[0, 2] = np.nan # Unstyled st._legacy_table(df) # Custom formatting st._legacy_table(df.style.format("{:.2%}")) # Colors st._legacy_table( df.style.applymap(color_negative_red).apply(highlight_max, color="darkorange", axis=0)) # Add rows x = st._legacy_table( df.style.set_properties(**{ "background-color": "black", "color": "lawngreen"
# Copyright 2018-2022 Streamlit Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import streamlit as st import pandas as pd import numpy as np grid = np.arange(0, 100, 1).reshape(10, 10) df = pd.DataFrame(grid) st._legacy_table(df)
st.header("Empty list") st.write([]) st.header("Empty dataframes") st.write(np.array(0)) st.write(pd.DataFrame([])) st._legacy_dataframe() st._legacy_dataframe([]) st._legacy_dataframe(np.array(0)) st._legacy_dataframe(pd.DataFrame([])) st.header("Empty one-column dataframes") st.write(np.array([])) st._legacy_dataframe(np.array([])) st.header("Empty two-column dataframes (only shows 1)") st.write(pd.DataFrame({"lat": [], "lon": []})) st._legacy_dataframe(pd.DataFrame({"lat": [], "lon": []})) st.header("Empty tables") st._legacy_table() st._legacy_table([]) st._legacy_table(np.array(0)) st._legacy_table(pd.DataFrame([])) st.header("Empty one-column table") st._legacy_table(np.array([])) st.header("Empty two-column table") st._legacy_table(pd.DataFrame({"lat": [], "lon": []}))
# * 2 line charts (one with only 1 datapoint) # * 4 vega-lite charts # * And then all of the above once again. # (Also, all of the above should have 3 rows or datapoints.) # * Then all of the above but with no data. # * Then a 1-row dataframe and an error num_rows = 3 df = pd.DataFrame({"a": [1, 2, 3], "b": [10, 0, 30], "c": [100, 200, -100]}) df1 = df.iloc[0:1, :] for test_type in ["coalesce in Py", "coalesce in JS", "clear after addrows"]: table_el = st._legacy_table(df1) dataframe_el = st._legacy_dataframe(df1) chart_el1 = st._legacy_line_chart() chart_el2 = st._legacy_line_chart(df1) # 4 identical charts, built in different ways. vega_el1 = st._legacy_vega_lite_chart( df1, { "mark": { "type": "line", "point": True }, "encoding": { "x": { "field": "a",
df = pd.DataFrame(np.random.randn(ROWS, cols), index=range(ROWS), columns=range(cols)) st._legacy_dataframe(df) st.header("Overriding st._legacy_dataframe") for cols in [4, 5, 6, 20]: df = pd.DataFrame(np.random.randn(ROWS, cols), index=range(ROWS), columns=range(cols)) df_elt = st._legacy_dataframe(np.random.randn(200, 200)) df_elt._legacy_dataframe(df) st.header("Using st._legacy_table") for cols in [4, 5, 6, 20]: df = pd.DataFrame(np.random.randn(ROWS, cols), index=range(ROWS), columns=range(cols)) st._legacy_table(df) st.header("Overriding st._legacy_table") for cols in [4, 5, 6, 20]: df = pd.DataFrame(np.random.randn(ROWS, cols), index=range(ROWS), columns=range(cols)) df_elt = st._legacy_table(np.random.randn(200, 200)) df_elt._legacy_table(df)