def test_legacy_line_chart(self): """Test dg._legacy_line_chart.""" data = pd.DataFrame([[20, 30, 50]], columns=["a", "b", "c"]) st._legacy_line_chart(data) element = self.get_delta_from_queue().new_element.vega_lite_chart chart_spec = json.loads(element.spec) self.assertEqual(chart_spec["mark"], "line") self.assertEqual(element.datasets[0].data.data.cols[2].int64s.data[0], 20)
def test_legacy_line_chart_with_generic_index(self): """Test dg._legacy_line_chart with a generic index.""" data = pd.DataFrame([[20, 30, 50]], columns=["a", "b", "c"]) data.set_index("a", inplace=True) st._legacy_line_chart(data) element = self.get_delta_from_queue().new_element.vega_lite_chart chart_spec = json.loads(element.spec) self.assertEqual(chart_spec["mark"], "line") self.assertEqual(element.datasets[0].data.data.cols[2].int64s.data[0], 30)
def test_st_legacy_line_chart(self): """Test st._legacy_line_chart.""" df = pd.DataFrame([[10, 20, 30]], columns=["a", "b", "c"]) st._legacy_line_chart(df, width=640, height=480) el = self.get_delta_from_queue().new_element.vega_lite_chart chart_spec = json.loads(el.spec) self.assertEqual(chart_spec["mark"], "line") self.assertEqual(chart_spec["width"], 640) self.assertEqual(chart_spec["height"], 480) self.assertEqual( el.datasets[0].data.columns.plain_index.data.strings.data, ["index", "variable", "value"], ) data = json.loads(json_format.MessageToJson(el.datasets[0].data.data)) result = [x["int64s"]["data"] for x in data["cols"] if "int64s" in x] self.assertEqual(result[1], ["10", "20", "30"])
def test_legacy_line_chart_with_pyarrow_table_data(self): """Test that an error is raised when called with `pyarrow.Table` data.""" df = pd.DataFrame([[20, 30, 50]], columns=["a", "b", "c"]) with self.assertRaises(StreamlitAPIException): st._legacy_line_chart(pa.Table.from_pandas(df))
data = pd.DataFrame({"a": [1, 2, 3, 4], "b": [1, 3, 2, 4]}) spec = { "mark": "line", "encoding": { "x": {"field": "a", "type": "quantitative"}, "y": {"field": "b", "type": "quantitative"}, }, } # 5 empty charts st._legacy_vega_lite_chart(spec, use_container_width=True) fig, ax = plt.subplots() st.pyplot(fig, use_container_width=True) st._legacy_line_chart() st._legacy_bar_chart() st._legacy_area_chart() # 1 empty map # comment this one out to avoid this Cypress-Mapbox related error. # ref: https://github.com/cypress-io/cypress/issues/4322 # st.pydeck_chart() # st.map() # 6 errors try: st._legacy_vega_lite_chart({}, use_container_width=True) except Exception as e: st.write(e)
# Copyright 2018-2021 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 numpy as np import pandas as pd data = np.random.randn(20, 3) df = pd.DataFrame(data, columns=["a", "b", "c"]) st._legacy_line_chart(df)
# * 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", "type": "quantitative" },
def _get_deltas_that_melt_dataframes(self): return [ lambda df: st._legacy_line_chart(df), lambda df: st._legacy_bar_chart(df), lambda df: st._legacy_area_chart(df), ]