vega / altair

Declarative statistical visualization library for Python
https://altair-viz.github.io/
BSD 3-Clause "New" or "Revised" License
9.39k stars 795 forks source link

unsupported narwhals import #3688

Closed mattijn closed 1 day ago

mattijn commented 1 day ago

What happened?

I currently get this error when trying to import altair:

ImportError: cannot import name 'is_into_dataframe' from 'narwhals.dependencies' 

This part is not safe at the moment: https://github.com/vega/altair/blob/a0c091eca897e1b9eaa6bb70d8ae8dc1deff9e60/altair/utils/_vegafusion_data.py#L8

The function is_into_dataframe is introduced in narwhals v1.13.1, but our demand is: https://github.com/vega/altair/blob/a0c091eca897e1b9eaa6bb70d8ae8dc1deff9e60/pyproject.toml#L23

Btw, should this not be referenced by making use of the stable v1 of narwhals?

import narwhals.stable.v1 as nw
...
return isinstance(data, DataFrameLike) or nw.dependencies.is_into_dataframe(data)

I notice elsewhere we mixed the stable.v1 with just-import-direct approach: https://github.com/vega/altair/blob/a0c091eca897e1b9eaa6bb70d8ae8dc1deff9e60/altair/utils/core.py#L18-L20

What would you like to happen instead?

Probably best is to update the pyproject.toml file.

Which version of Altair are you using?

main