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

Simplify Altair import #2479

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Changes from all 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
24 changes: 5 additions & 19 deletions splink/internals/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@
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, 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):
Expand All @@ -42,13 +33,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

Expand Down
Loading