From 6103ad791b90cf7420bf8f7bbfd5d73ca25ab769 Mon Sep 17 00:00:00 2001 From: ADBond <48208438+ADBond@users.noreply.github.com> Date: Mon, 21 Oct 2024 17:24:05 +0100 Subject: [PATCH 1/2] make altair import explicit altair is a core requirement, and this fails anyway if altair not installed, just more mysteriously --- splink/internals/charts.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/splink/internals/charts.py b/splink/internals/charts.py index d6a6cc2dc2..1d4a242637 100644 --- a/splink/internals/charts.py +++ b/splink/internals/charts.py @@ -3,26 +3,18 @@ import json import math import os -from typing import TYPE_CHECKING, Any, Dict, Union +from typing import Any, Dict, Union import numpy as np import pandas as pd +from altair import Chart +from altair.core import SchemaBase from splink.internals.misc import read_resource from splink.internals.waterfall_chart import records_to_waterfall_data -altair_installed = True - -try: - import altair as alt -except ImportError: - altair_installed = False - -if TYPE_CHECKING: - import altair as alt - # type alias: -ChartReturnType = Union[Dict[Any, Any], alt.core.SchemaBase] +ChartReturnType = Union[Dict[Any, Any], SchemaBase] def load_chart_definition(filename): @@ -42,13 +34,8 @@ def _load_external_libs(): def altair_or_json( chart_dict: dict[Any, Any], as_dict: bool = False ) -> ChartReturnType: - if altair_installed: - if not as_dict: - try: - return alt.Chart.from_dict(chart_dict) - - except ModuleNotFoundError: - return chart_dict + if not as_dict: + return Chart.from_dict(chart_dict) return chart_dict From 459d7a0c8c691da905804075e6a62d7d1239aa83 Mon Sep 17 00:00:00 2001 From: ADBond <48208438+ADBond@users.noreply.github.com> Date: Tue, 22 Oct 2024 07:42:37 +0100 Subject: [PATCH 2/2] fix import --- splink/internals/charts.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/splink/internals/charts.py b/splink/internals/charts.py index 1d4a242637..fd5efb5b8d 100644 --- a/splink/internals/charts.py +++ b/splink/internals/charts.py @@ -7,8 +7,7 @@ import numpy as np import pandas as pd -from altair import Chart -from altair.core import SchemaBase +from altair import Chart, SchemaBase from splink.internals.misc import read_resource from splink.internals.waterfall_chart import records_to_waterfall_data