Skip to content

Commit

Permalink
Merge branch 'main' into maps-faceted-species
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned authored Feb 22, 2025
2 parents 2c4bde2 + a196172 commit 1bc3c36
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 27 deletions.
4 changes: 2 additions & 2 deletions altair/expr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ class expr(_ExprRef, metaclass=_ExprMeta):
``ExprRef``
.. _Expressions:
https://altair-viz.github.io/user_guide/interactions.html#expressions
https://altair-viz.github.io/user_guide/interactions/expressions.html
.. _inline expression:
https://altair-viz.github.io/user_guide/interactions.html#inline-expressions
https://altair-viz.github.io/user_guide/interactions/expressions.html#inline-expressions
.. _vega expression:
https://vega.github.io/vega/docs/expressions/
Expand Down
6 changes: 4 additions & 2 deletions altair/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
from altair.utils._dfi_types import DataFrame as DfiDataFrame
from altair.vegalite.v5.schema._typing import StandardType_T as InferredVegaLiteType

_PandasDataFrameT = TypeVar("_PandasDataFrameT", bound="pd.DataFrame")

TIntoDataFrame = TypeVar("TIntoDataFrame", bound=IntoDataFrame)
T = TypeVar("T")
P = ParamSpec("P")
Expand Down Expand Up @@ -328,7 +330,7 @@ def numpy_is_subtype(dtype: Any, subtype: Any) -> bool:
return False


def sanitize_pandas_dataframe(df: pd.DataFrame) -> pd.DataFrame: # noqa: C901
def sanitize_pandas_dataframe(df: _PandasDataFrameT) -> _PandasDataFrameT: # noqa: C901
"""
Sanitize a DataFrame to prepare it for serialization.
Expand All @@ -351,7 +353,7 @@ def sanitize_pandas_dataframe(df: pd.DataFrame) -> pd.DataFrame: # noqa: C901
import numpy as np
import pandas as pd

df = df.copy()
df = cast("_PandasDataFrameT", df.copy())

if isinstance(df.columns, pd.RangeIndex):
df.columns = df.columns.astype(str)
Expand Down
16 changes: 6 additions & 10 deletions altair/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,16 @@ def _compute_data_hash(data_str: str) -> str:
return hashlib.sha256(data_str.encode()).hexdigest()[:32]


def _from_geo_interface(data: SupportsGeoInterface | Any) -> dict[str, Any]:
def _from_geo_interface(data: SupportsGeoInterface) -> dict[str, Any]:
"""
Santize a ``__geo_interface__`` w/ pre-santize step for ``pandas`` if needed.
Notes
-----
Split out to resolve typing issues related to:
- Intersection types
- ``typing.TypeGuard``
- ``pd.DataFrame.__getattr__``
Introduces an intersection type::
geo: <subclass of SupportsGeoInterface and DataFrame> | SupportsGeoInterface
"""
if is_pandas_dataframe(data):
data = sanitize_pandas_dataframe(data)
return sanitize_geo_interface(data.__geo_interface__)
geo = sanitize_pandas_dataframe(data) if is_pandas_dataframe(data) else data
return sanitize_geo_interface(geo.__geo_interface__)


def _data_to_json_string(data: DataType) -> str:
Expand Down
2 changes: 1 addition & 1 deletion altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ def param(
**kwds: Any,
) -> Parameter:
"""
Create a named parameter, see https://altair-viz.github.io/user_guide/interactions.html for examples.
Create a named parameter, see https://altair-viz.github.io/user_guide/interactions/parameters.html for examples.
Although both variable parameters and selection parameters can be created using
this 'param' function, to create a selection parameter, it is recommended to use
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies = [
# If you update the minimum required jsonschema version, also update it in build.yml
"jsonschema>=3.0",
"packaging",
"narwhals>=1.25.1"
"narwhals>=1.27.1"
]
description = "Vega-Altair: A declarative statistical visualization library for Python."
readme = "README.md"
Expand Down
6 changes: 1 addition & 5 deletions tests/vegalite/v5/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,7 @@ def test_when_labels_position_based_on_condition() -> None:


def test_when_expressions_inside_parameters() -> None:
"""
Test for [2144026368-2](https://github.com/vega/altair/pull/3427#issuecomment-2144026368).
Original [expressions-inside-parameters](https://altair-viz.github.io/user_guide/interactions.html#expressions-inside-parameters)
"""
"""Test for [2144026368-2](https://github.com/vega/altair/pull/3427#issuecomment-2144026368)."""
import polars as pl

source = pl.DataFrame({"a": ["A", "B", "C"], "b": [28, -5, 10]})
Expand Down
4 changes: 2 additions & 2 deletions tools/vega_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ def PI(cls) -> {return_ann}:
``ExprRef``
.. _Expressions:
https://altair-viz.github.io/user_guide/interactions.html#expressions
https://altair-viz.github.io/user_guide/interactions/expressions.html
.. _inline expression:
https://altair-viz.github.io/user_guide/interactions.html#inline-expressions
https://altair-viz.github.io/user_guide/interactions/expressions.html#inline-expressions
.. _vega expression:
https://vega.github.io/vega/docs/expressions/
Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1bc3c36

Please sign in to comment.