Skip to content

Commit

Permalink
Add forward compatibility with Altair 5 (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmmease authored Jan 21, 2023
1 parent 6bc9598 commit c3faae5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion python/vegafusion/vegafusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ def altair_vl_version(vl_convert=False):
(e.g. v4_17 rather than 4.17.0)
:return: str with Vega-Lite version
"""
from altair.vegalite.v4 import SCHEMA_VERSION
try:
# Altair 5
from altair.vegalite.v5 import SCHEMA_VERSION
except ImportError:
# Altair 4
from altair.vegalite.v4 import SCHEMA_VERSION

if vl_convert:
# Compute VlConvert's vl_version string (of the form 'v5_2')
# from SCHEMA_VERSION (of the form 'v5.2.0')
Expand Down
10 changes: 8 additions & 2 deletions python/vegafusion/vegafusion/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import json

from altair import data_transformers
from altair.vegalite.v4.api import Chart, FacetChart
from altair.utils.schemapi import Undefined

try:
# Altair 5 imports
from altair.vegalite.v5.api import Chart, FacetChart
except ImportError:
# Altair 4 imports
from altair.vegalite.v4.api import Chart, FacetChart

MAGIC_MARK_NAME = "_vf_mark"


Expand All @@ -12,7 +18,7 @@ def transformed_data(chart: Chart, row_limit=None):
Evaluate the transform associated with a Chart and return the transformed
data as a DataFrame
:param chart: altair.vegalite.v4.api.Chart object
:param chart: altair Chart object
:param row_limit: Maximum number of rows to return. None (default) for unlimited
:return: pandas DataFrame of transformed data
"""
Expand Down

0 comments on commit c3faae5

Please sign in to comment.