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

[Test] Update vizro ai integration test for dataclass output #518

Merged
merged 7 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!--
A new scriv changelog fragment.

Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨

- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Removed
Anna-Xiong marked this conversation as resolved.
Show resolved Hide resolved

- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Added

- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Changed

- A bullet item for the Changed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Deprecated

- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Fixed

- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
<!--
### Security

- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1))

-->
8 changes: 0 additions & 8 deletions vizro-ai/src/vizro_ai/_vizro_ai.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from dataclasses import asdict
from typing import Any, Optional, Union

import pandas as pd
Expand All @@ -25,7 +24,6 @@ class VizroAI:
"""Vizro-AI main class."""

pipeline_manager: PipelineManager = PipelineManager()
_return_all_text: bool = False # TODO deleted after adding new integration test

def __init__(self, model: Optional[Union[ChatOpenAI, str]] = None):
"""Initialization of VizroAI.
Expand Down Expand Up @@ -153,10 +151,4 @@ def plot( # pylint: disable=too-many-arguments # noqa: PLR0913
code_explain=vizro_plot.code_explanation,
)

# TODO Tentative for integration test, will be updated/removed for new tests
if self._return_all_text:
output_dict = asdict(vizro_plot)
output_dict["code_string"] = vizro_plot.code
return output_dict

return vizro_plot if return_elements else vizro_plot.figure
28 changes: 16 additions & 12 deletions vizro-ai/tests/integration/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,48 @@


def test_chart():
vizro_ai._return_all_text = True
resp = vizro_ai.plot(df, "describe the composition of scatter chart with gdp in continent")
resp = vizro_ai.plot(
df=df,
user_input="describe the composition of scatter chart with gdp in continent",
explain=False,
return_elements=True,
)
assert_that(
resp["code_string"],
resp.code,
all_of(contains_string("px.scatter")),
)
assert_that(
resp["code_string"],
resp.code,
any_of(contains_string("x='continent'"), contains_string("x='gdpPercap'")),
)
assert_that(
resp["code_string"],
resp.code,
any_of(contains_string("y='count'"), contains_string("y='gdpPercap'"), contains_string("y='continent'")),
)
assert_that(resp["business_insights"], equal_to(None))
assert_that(resp["code_explanation"], equal_to(None))
assert_that(resp.code_explanation, equal_to(None))
assert_that(resp.business_insights, equal_to(None))


def test_chart_with_explanation():
vizro_ai._return_all_text = True
resp = vizro_ai.plot(df, "describe the composition of gdp in US", explain=True)
resp = vizro_ai.plot(df, "describe the composition of gdp in US", explain=True, return_elements=True)
assert_that(
resp["code_string"],
resp.code,
all_of(contains_string("px.bar"), contains_string("x='year'")),
)
assert_that(
resp["code_string"],
resp.code,
any_of(contains_string("y='gdpPercap'"), contains_string("y='total_gdp'")),
)
assert_that(
resp["business_insights"],
resp.business_insights,
any_of(
contains_string("GDP per capita in the United States"),
contains_string("GDP in the United States"),
contains_string("GDP in the US"),
),
)
assert_that(
resp["code_explanation"],
resp.code_explanation,
all_of(contains_string("https://vizro.readthedocs.io/en/stable/pages/user_guides/custom_charts/")),
)
Loading