Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix-use-signature-2
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Sep 3, 2024
2 parents fb1fe81 + db97a0b commit 73b39ac
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
5 changes: 1 addition & 4 deletions altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
compile_with_vegafusion as _compile_with_vegafusion,
)
from altair.utils._vegafusion_data import using_vegafusion as _using_vegafusion
from altair.utils.core import (
to_eager_narwhals_dataframe as _to_eager_narwhals_dataframe,
)
from altair.utils.data import DataType
from altair.utils.data import is_data_type as _is_data_type

Expand Down Expand Up @@ -1822,7 +1819,7 @@ def to_dict( # noqa: C901
original_data = getattr(copy, "data", Undefined)
if not utils.is_undefined(original_data):
try:
data = _to_eager_narwhals_dataframe(original_data)
data = nw.from_native(original_data, eager_or_interchange_only=True)
except TypeError:
# Non-narwhalifiable type supported by Altair, such as dict
data = original_data
Expand Down
37 changes: 36 additions & 1 deletion tests/vegalite/v5/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import re
import sys
import tempfile
from datetime import date
from datetime import date, datetime
from importlib.metadata import version as importlib_version

import ibis
Expand Down Expand Up @@ -1548,3 +1548,38 @@ def test_ibis_with_date_32():
{"a": 2, "b": "2020-01-02T00:00:00"},
{"a": 3, "b": "2020-01-03T00:00:00"},
]


@pytest.mark.skipif(
sys.version_info < (3, 9),
reason="The maximum `ibis` version installable on Python 3.8 is `ibis==5.1.0`,"
" which doesn't support the dataframe interchange protocol.",
)
@pytest.mark.skipif(
Version("1.5") > PANDAS_VERSION,
reason="A warning is thrown on old pandas versions",
)
@pytest.mark.xfail(
sys.platform == "win32", reason="Timezone database is not installed on Windows"
)
def test_ibis_with_vegafusion(monkeypatch: pytest.MonkeyPatch):
df = pl.DataFrame(
{
"a": [1, 2, 3],
"b": [datetime(2020, 1, 1), datetime(2020, 1, 2), datetime(2020, 1, 3)],
}
)
tbl = ibis.memtable(df)
# "poison" `arrow_table_from_dfi_dataframe` to check that it does not get called
# if we use the vegafusion transformer
monkeypatch.setattr(
"altair.utils.data.arrow_table_from_dfi_dataframe", lambda x: 1 / 0
)
tbl = ibis.memtable(df)
with alt.data_transformers.enable("vegafusion"):
result = alt.Chart(tbl).mark_line().encode(x="a", y="b").to_dict(format="vega")
assert next(iter(result["data"]))["values"] == [
{"a": 1, "b": "2020-01-01T00:00:00.000"},
{"a": 2, "b": "2020-01-02T00:00:00.000"},
{"a": 3, "b": "2020-01-03T00:00:00.000"},
]

0 comments on commit 73b39ac

Please sign in to comment.