Skip to content

Commit

Permalink
ci: bump narwhals>=1.27.1 (#3807)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned authored Feb 17, 2025
1 parent f61a22e commit f1e0049
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
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 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.26.0"
"narwhals>=1.27.1"
]
description = "Vega-Altair: A declarative statistical visualization library for Python."
readme = "README.md"
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 f1e0049

Please sign in to comment.