Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into shorthand-namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned committed Aug 13, 2024
2 parents e449796 + 95f5d31 commit daeb895
Show file tree
Hide file tree
Showing 84 changed files with 3,123 additions and 977 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto
* text=auto eol=lf
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
pip install pandas==0.25.3 numpy==1.17.5
- name: Test that schema generation has no effect
run: |
pip install vl-convert-python
python tools/generate_schema_wrapper.py
# This gets the paths of all files which were either deleted, modified
# or are not yet tracked by Git
Expand All @@ -60,6 +61,7 @@ jobs:
if [ ${#files_cleaned[@]} -gt 0 ]; then
echo "The code generation modified the following files:"
echo $files
git diff
exit 1
fi
- name: Test with pytest
Expand Down
9 changes: 4 additions & 5 deletions altair/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ruff: noqa
__version__ = "5.4.0dev"
__version__ = "5.5.0dev"

# The content of __all__ is automatically written by
# tools/update_init_file.py. Do not modify directly.
Expand Down Expand Up @@ -50,7 +50,6 @@
"ChainedWhen",
"Chart",
"ChartDataType",
"ChartType",
"Color",
"ColorDatum",
"ColorDef",
Expand Down Expand Up @@ -301,7 +300,6 @@
"Opacity",
"OpacityDatum",
"OpacityValue",
"Optional",
"Order",
"OrderFieldDef",
"OrderOnlyDef",
Expand Down Expand Up @@ -613,7 +611,6 @@
"field",
"graticule",
"hconcat",
"is_chart_type",
"jupyter",
"layer",
"limit_rows",
Expand All @@ -636,6 +633,7 @@
"to_json",
"to_values",
"topo_feature",
"typing",
"utils",
"v5",
"value",
Expand All @@ -655,7 +653,8 @@ def __dir__():
from altair.vegalite.v5.schema.core import Dict
from altair.jupyter import JupyterChart
from altair.expr import expr
from altair.utils import AltairDeprecationWarning, parse_shorthand, Optional, Undefined
from altair.utils import AltairDeprecationWarning, parse_shorthand, Undefined
from altair import typing


def load_ipython_extension(ipython):
Expand Down
1 change: 0 additions & 1 deletion altair/expr/consts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations


CONST_LISTING = {
"NaN": "not a number (same as JavaScript literal NaN)",
"LN10": "the natural log of 10 (alias to Math.LN10)",
Expand Down
10 changes: 8 additions & 2 deletions altair/expr/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations
from typing import Any
from ..utils import SchemaBase

from typing import Any, Dict, Union
from typing_extensions import TypeAlias

from altair.utils import SchemaBase


class DatumType:
Expand Down Expand Up @@ -232,3 +235,6 @@ def __init__(self, group, name) -> None:

def __repr__(self) -> str:
return f"{self.group}[{self.name!r}]"


IntoExpression: TypeAlias = Union[bool, None, str, OperatorMixin, Dict[str, Any]]
2 changes: 1 addition & 1 deletion altair/jupyter/js/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import vegaEmbed from "https://esm.sh/vega-embed@6?deps=vega@5&deps=vega-lite@5.19.0";
import vegaEmbed from "https://esm.sh/vega-embed@6?deps=vega@5&deps=vega-lite@5.20.1";
import lodashDebounce from "https://esm.sh/[email protected]/debounce";

// Note: For offline support, the import lines above are removed and the remaining script
Expand Down
14 changes: 8 additions & 6 deletions altair/jupyter/jupyter_chart.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from __future__ import annotations

import json
import anywidget
import traitlets
import pathlib
from typing import Any

import anywidget
import traitlets

import altair as alt
from altair import TopLevelSpec
from altair.utils._vegafusion_data import (
using_vegafusion,
compile_to_vegafusion_chart_state,
using_vegafusion,
)
from altair import TopLevelSpec
from altair.utils.selection import IndexSelection, PointSelection, IntervalSelection
from altair.utils.selection import IndexSelection, IntervalSelection, PointSelection

_here = pathlib.Path(__file__).parent

Expand Down Expand Up @@ -216,7 +218,7 @@ def __init__(
)

@traitlets.observe("chart")
def _on_change_chart(self, change):
def _on_change_chart(self, change): # noqa: C901
"""Updates the JupyterChart's internal state when the wrapped Chart instance changes."""
new_chart = change.new
selection_watches = []
Expand Down
96 changes: 96 additions & 0 deletions altair/typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""Public types to ease integrating with `altair`."""

from __future__ import annotations

__all__ = [
"ChannelAngle",
"ChannelColor",
"ChannelColumn",
"ChannelDescription",
"ChannelDetail",
"ChannelFacet",
"ChannelFill",
"ChannelFillOpacity",
"ChannelHref",
"ChannelKey",
"ChannelLatitude",
"ChannelLatitude2",
"ChannelLongitude",
"ChannelLongitude2",
"ChannelOpacity",
"ChannelOrder",
"ChannelRadius",
"ChannelRadius2",
"ChannelRow",
"ChannelShape",
"ChannelSize",
"ChannelStroke",
"ChannelStrokeDash",
"ChannelStrokeOpacity",
"ChannelStrokeWidth",
"ChannelText",
"ChannelTheta",
"ChannelTheta2",
"ChannelTooltip",
"ChannelUrl",
"ChannelX",
"ChannelX2",
"ChannelXError",
"ChannelXError2",
"ChannelXOffset",
"ChannelY",
"ChannelY2",
"ChannelYError",
"ChannelYError2",
"ChannelYOffset",
"ChartType",
"EncodeKwds",
"Optional",
"is_chart_type",
]

from altair.utils.schemapi import Optional
from altair.vegalite.v5.api import ChartType, is_chart_type
from altair.vegalite.v5.schema.channels import (
ChannelAngle,
ChannelColor,
ChannelColumn,
ChannelDescription,
ChannelDetail,
ChannelFacet,
ChannelFill,
ChannelFillOpacity,
ChannelHref,
ChannelKey,
ChannelLatitude,
ChannelLatitude2,
ChannelLongitude,
ChannelLongitude2,
ChannelOpacity,
ChannelOrder,
ChannelRadius,
ChannelRadius2,
ChannelRow,
ChannelShape,
ChannelSize,
ChannelStroke,
ChannelStrokeDash,
ChannelStrokeOpacity,
ChannelStrokeWidth,
ChannelText,
ChannelTheta,
ChannelTheta2,
ChannelTooltip,
ChannelUrl,
ChannelX,
ChannelX2,
ChannelXError,
ChannelXError2,
ChannelXOffset,
ChannelY,
ChannelY2,
ChannelYError,
ChannelYError2,
ChannelYOffset,
EncodeKwds,
)
19 changes: 9 additions & 10 deletions altair/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from .core import (
infer_vegalite_type_for_pandas,
SHORTHAND_KEYS,
SchemaBase,
display_traceback,
infer_encoding_types,
sanitize_pandas_dataframe,
sanitize_narwhals_dataframe,
infer_vegalite_type_for_pandas,
parse_shorthand,
use_signature,
sanitize_narwhals_dataframe,
sanitize_pandas_dataframe,
update_nested,
display_traceback,
SchemaBase,
SHORTHAND_KEYS,
use_signature,
)
from .deprecation import AltairDeprecationWarning, deprecated, deprecated_warn
from .html import spec_to_html
from .plugin_registry import PluginRegistry
from .deprecation import AltairDeprecationWarning, deprecated, deprecated_warn
from .schemapi import Undefined, Optional, is_undefined

from .schemapi import Optional, Undefined, is_undefined

__all__ = (
"SHORTHAND_KEYS",
Expand Down
1 change: 1 addition & 0 deletions altair/utils/_dfi_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#
# These classes are only for use in type signatures
from __future__ import annotations

import enum
from typing import Any, Iterable, Protocol

Expand Down
4 changes: 2 additions & 2 deletions altair/utils/_importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def import_vegafusion() -> ModuleType:


def import_vl_convert() -> ModuleType:
min_version = "1.5.0"
min_version = "1.6.0"
try:
version = importlib_version("vl-convert-python")
if Version(version) < Version(min_version):
Expand All @@ -67,7 +67,7 @@ def import_vl_convert() -> ModuleType:


def vl_version_for_vl_convert() -> str:
from ..vegalite import SCHEMA_VERSION
from altair.vegalite import SCHEMA_VERSION

# Compute VlConvert's vl_version string (of the form 'v5_2')
# from SCHEMA_VERSION (of the form 'v5.2.0')
Expand Down
1 change: 1 addition & 0 deletions altair/utils/_show.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations

import webbrowser
from http.server import BaseHTTPRequestHandler, HTTPServer
from typing import Iterable
Expand Down
38 changes: 20 additions & 18 deletions altair/utils/_transformed_data.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
from __future__ import annotations
from typing import Any, Iterable, overload, TYPE_CHECKING, Dict, Tuple

from typing import TYPE_CHECKING, Any, Dict, Iterable, Tuple, overload
from typing_extensions import TypeAlias

from altair import (
Chart,
FacetChart,
LayerChart,
HConcatChart,
VConcatChart,
ConcatChart,
TopLevelUnitSpec,
ConcatSpecGenericSpec,
FacetChart,
FacetedUnitSpec,
UnitSpec,
UnitSpecWithFrame,
NonNormalizedSpec,
TopLevelLayerSpec,
FacetSpec,
HConcatChart,
HConcatSpecGenericSpec,
LayerChart,
LayerSpec,
NonNormalizedSpec,
TopLevelConcatSpec,
ConcatSpecGenericSpec,
TopLevelFacetSpec,
TopLevelHConcatSpec,
HConcatSpecGenericSpec,
TopLevelLayerSpec,
TopLevelUnitSpec,
TopLevelVConcatSpec,
UnitSpec,
UnitSpecWithFrame,
VConcatChart,
VConcatSpecGenericSpec,
TopLevelFacetSpec,
FacetSpec,
data_transformers,
)
from altair.utils._vegafusion_data import get_inline_tables, import_vegafusion
from altair.utils.schemapi import Undefined

if TYPE_CHECKING:
from altair.typing import ChartType
from altair.utils.core import DataFrameLike

Scope: TypeAlias = Tuple[int, ...]
Expand Down Expand Up @@ -154,9 +157,7 @@ def transformed_data(chart, row_limit=None, exclude=None):
# The same error appeared when trying it with Protocols for the concat and layer charts.
# This function is only used internally and so we accept this inconsistency for now.
def name_views(
chart: Chart | FacetChart | LayerChart | HConcatChart | VConcatChart | ConcatChart,
i: int = 0,
exclude: Iterable[str] | None = None,
chart: ChartType, i: int = 0, exclude: Iterable[str] | None = None
) -> list[str]:
"""
Name unnamed chart views.
Expand Down Expand Up @@ -193,6 +194,7 @@ def name_views(
else:
return []
else:
subcharts: list[Any]
if isinstance(chart, _chart_class_mapping[LayerChart]):
subcharts = chart.layer
elif isinstance(chart, _chart_class_mapping[HConcatChart]):
Expand Down Expand Up @@ -450,7 +452,7 @@ def get_facet_mapping(group: dict[str, Any], scope: Scope = ()) -> FacetMapping:
group, facet_data, scope
)
if definition_scope is not None:
facet_mapping[(facet_name, group_scope)] = (
facet_mapping[facet_name, group_scope] = (
facet_data,
definition_scope,
)
Expand Down
Loading

0 comments on commit daeb895

Please sign in to comment.