From 6ff3ad2d4a8eebb4e2c65c4a5d7147da8b112478 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Fri, 25 Mar 2022 16:44:13 -0700 Subject: [PATCH] output tests passing --- gradio/components.py | 13 ++++++++----- test/test_inputs.py | 4 ++-- test/test_outputs.py | 14 ++++++++++---- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/gradio/components.py b/gradio/components.py index 9ee9aa469c..2b8d4716c4 100644 --- a/gradio/components.py +++ b/gradio/components.py @@ -1988,7 +1988,7 @@ class Dataframe(Component): ): """ Input Parameters: - default_value (List[List[Any]]): Default value + default_value (List[List[Any]]): Default value as a pandas DataFrame. TODO: Add support for default value as a filepath headers (List[str]): Header names to dataframe. If None, no headers are shown. row_count (int): Limit number of rows for input. col_count (int): Limit number of columns for input. If equal to 1, return data will be one-dimensional. Ignored if `headers` is provided. @@ -2150,7 +2150,7 @@ class Timeseries(Component): def __init__( self, - default_value: str = "", + default_value: Optional[str] = None, *, x: Optional[str] = None, y: str | List[str] = None, @@ -2160,13 +2160,16 @@ class Timeseries(Component): ): """ Parameters: - default_value: File path for the timeseries csv file. + default_value: File path for the timeseries csv file. TODO: Add support for default value as a pd.DataFrame x (str): Column name of x (time) series. None if csv has no headers, in which case first column is x series. y (Union[str, List[str]]): Column name of y series, or list of column names if multiple series. None if csv has no headers, in which case every column after first is a y series. label (str): component name in interface. """ - # TODO: Probably incorrect - self.default_value = pd.DataFrame(default_value) + self.default_value = ( + pd.read_csv(default_value) + if default_value is not None + else None + ) self.x = x if isinstance(y, str): y = [y] diff --git a/test/test_inputs.py b/test/test_inputs.py index 720fbcca9d..2ca3f25dcf 100644 --- a/test/test_inputs.py +++ b/test/test_inputs.py @@ -130,7 +130,7 @@ class TestNumber(unittest.TestCase): ) self.assertEqual( numeric_input.get_template_context(), - {"default": None, "name": "number", "label": None, "css": {}}, + {"default_value": None, "name": "number", "label": None, "css": {}}, ) def test_in_interface(self): @@ -191,7 +191,7 @@ class TestSlider(unittest.TestCase): "minimum": 10, "maximum": 20, "step": 1, - "default": 15, + "default_value": 15, "name": "slider", "label": "Slide Your Input", "css": {}, diff --git a/test/test_outputs.py b/test/test_outputs.py index 16813b8d21..c2bd837d72 100644 --- a/test/test_outputs.py +++ b/test/test_outputs.py @@ -184,6 +184,7 @@ class TestHighlightedText(unittest.TestCase): "label": None, "show_legend": False, "css": {}, + "default_value": "" }, ) ht = {"pos": "Hello ", "neg": "World"} @@ -231,7 +232,11 @@ class TestAudio(unittest.TestCase): ) self.assertEqual( audio_output.get_template_context(), - {"name": "audio", "label": None, "source": "upload", "css": {}}, + {"name": "audio", + "label": None, + "source": "upload", + "css": {}, + "default_value": None}, ) self.assertTrue( audio_output.deserialize(gr.test_data.BASE64_AUDIO["data"]).endswith(".wav") @@ -357,7 +362,7 @@ class TestDataframe(unittest.TestCase): "row_count": 3, "col_count": 3, "col_width": None, - "default": [[None, None, None], [None, None, None], [None, None, None]], + "default_value": [[None, None, None], [None, None, None], [None, None, None]], "name": "dataframe", }, ) @@ -423,7 +428,7 @@ class TestCarousel(unittest.TestCase): { "name": "textbox", "label": None, - "default": "", + "default_value": "", "lines": 1, "css": {}, "placeholder": None, @@ -482,7 +487,8 @@ class TestTimeseries(unittest.TestCase): timeseries_output = gr.outputs.Timeseries(label="Disease") self.assertEqual( timeseries_output.get_template_context(), - {"x": None, "y": None, "name": "timeseries", "label": "Disease", "css": {}}, + {"x": None, "y": None, "name": "timeseries", "label": "Disease", "css": {}, + "default_value": None}, ) data = {"Name": ["Tom", "nick", "krish", "jack"], "Age": [20, 21, 19, 18]} df = pd.DataFrame(data)