Skip to content

Commit

Permalink
refactor: Remove channels parameter in infer_encoding_types
Browse files Browse the repository at this point in the history
Was kept, but only needed for tests since vega#3444.
As `infer_encoding_types` is not public API - this is a safe remove, no need for deprecation
  • Loading branch information
dangotbanned committed Sep 1, 2024
1 parent 0aa67b8 commit 0de7643
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions altair/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

if TYPE_CHECKING:
import typing as t
from types import ModuleType

import pandas as pd
from narwhals.typing import IntoExpr
Expand Down Expand Up @@ -812,22 +811,6 @@ class _ChannelCache:
channel_to_name: dict[type[SchemaBase], str]
name_to_channel: dict[str, dict[_ChannelType, type[SchemaBase]]]

@classmethod
def from_channels(cls, channels: ModuleType, /) -> _ChannelCache:
# - This branch is only kept for tests that depend on mocking `channels`.
# - No longer needs to pass around `channels` reference and rebuild every call.
c_to_n = {
c: c._encoding_name
for c in channels.__dict__.values()
if isinstance(c, type)
and issubclass(c, SchemaBase)
and hasattr(c, "_encoding_name")
}
self = cls.__new__(cls)
self.channel_to_name = c_to_n
self.name_to_channel = _invert_group_channels(c_to_n)
return self

@classmethod
def from_cache(cls) -> _ChannelCache:
global _CHANNEL_CACHE
Expand Down Expand Up @@ -925,9 +908,7 @@ def _reduce(it: Iterator[tuple[type[Any], str]]) -> Any:
return {k: _reduce(chans) for k, chans in grouper}


def infer_encoding_types(
args: tuple[Any, ...], kwargs: dict[str, Any], channels: ModuleType | None = None
):
def infer_encoding_types(args: tuple[Any, ...], kwargs: dict[str, Any]):
"""
Infer typed keyword arguments for args and kwargs.
Expand All @@ -937,20 +918,14 @@ def infer_encoding_types(
Sequence of function args
kwargs : MutableMapping
Dict of function kwargs
channels : ModuleType
The module containing all altair encoding channel classes.
Returns
-------
kwargs : dict
All args and kwargs in a single dict, with keys and types
based on the channels mapping.
"""
cache = (
_ChannelCache.from_channels(channels)
if channels
else _ChannelCache.from_cache()
)
cache = _ChannelCache.from_cache()
# First use the mapping to convert args to kwargs based on their types.
for arg in args:
el = next(iter(arg), None) if isinstance(arg, (list, tuple)) else arg
Expand Down

0 comments on commit 0de7643

Please sign in to comment.