Skip to content

Commit

Permalink
Merge branch 'main' into versioning-policy
Browse files Browse the repository at this point in the history
  • Loading branch information
dangotbanned authored Jul 27, 2024
2 parents 68a7a52 + 1939ebd commit 170ba3b
Show file tree
Hide file tree
Showing 7 changed files with 3,206 additions and 3,685 deletions.
3,353 changes: 1,568 additions & 1,785 deletions altair/vegalite/v5/schema/channels.py

Large diffs are not rendered by default.

3,474 changes: 1,595 additions & 1,879 deletions altair/vegalite/v5/schema/core.py

Large diffs are not rendered by default.

8 changes: 0 additions & 8 deletions doc/user_guide/customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -823,14 +823,6 @@ The preferred format of numbers, dates, and currencies varies by language and lo
Vega-Altair takes advantage of `D3's localization support`_ to make it easy to configure
the locale for your chart using the global ``alt.renderers.set_embed_options`` function.

.. altair-plot::
:output: none

import altair as alt
alt.renderers.set_embed_options(
format_locale=format_locale, time_format_locale=time_format_locale
)

Here ``format_locale`` and ``time_format_locale`` may either be D3 format dictionaries,
or strings with the names of pre-defined locales. For example, here we use the
Italian locale (named ``it-IT``) for both currencies and dates:
Expand Down
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ all = [
"vega_datasets>=0.9.0",
"vl-convert-python>=1.5.0",
"pandas>=0.25.3",
"numpy<2.0.0",
"numpy",
"pyarrow>=11",
"vegafusion[embed]>=1.6.6",
"anywidget>=0.9.0",
Expand All @@ -73,7 +73,7 @@ dev = [
"pytest",
"pytest-cov",
"pytest-xdist[psutil]~=3.5",
"m2r",
"mistune",
"mypy",
"pandas-stubs",
"types-jsonschema",
Expand Down Expand Up @@ -305,6 +305,8 @@ select = [
"D",
# multi-line-summary-second-line
"D213",
# numpy-specific-rules
"NPY",
]
ignore = [
# Whitespace before ':'
Expand Down
3 changes: 2 additions & 1 deletion tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def _check(arr, typ):
_check(pd.date_range("2012", "2013"), "temporal")
_check(pd.timedelta_range(365, periods=12), "temporal")

nulled = pd.Series(np.random.randint(10, size=10))
rng = np.random.default_rng()
nulled = pd.Series(rng.integers(10, size=10))
nulled[0] = None
_check(nulled, "quantitative")
_check(["a", "b", "c"], "nominal")
Expand Down
14 changes: 4 additions & 10 deletions tools/generate_schema_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from typing import Final, Iterable, Literal, Iterator
from itertools import chain
from urllib import request
import m2r

sys.path.insert(0, str(Path.cwd()))
from tools.schemapi import codegen, CodeSnippet, SchemaInfo
Expand All @@ -23,6 +22,7 @@
rst_syntax_for_class,
indent_docstring,
ruff_write_lint_format_str,
rst_parse,
)


Expand Down Expand Up @@ -271,26 +271,20 @@ def _process_description(description: str) -> str:


def process_description(description: str) -> str:
# remove formatting from links
description = "".join(
[
reSpecial.sub("", d) if i % 2 else d
for i, d in enumerate(reLink.split(description))
]
) # remove formatting from links
description = m2r.convert(description)
description = description.replace(m2r.prolog, "")
description = description.replace(":raw-html-m2r:", ":raw-html:")
description = description.replace(r"\ ,", ",")
description = description.replace(r"\ ", " ")
# turn explicit references into anonymous references
description = description.replace(">`_", ">`__")
)
description = rst_parse(description)
# Some entries in the Vega-Lite schema miss the second occurence of '__'
description = description.replace("__Default value: ", "__Default value:__ ")
# Fixing ambiguous unicode, RUF001 produces RUF002 in docs
description = description.replace("’", "'") # noqa: RUF001 [RIGHT SINGLE QUOTATION MARK]
description = description.replace("–", "-") # noqa: RUF001 [EN DASH]
description = description.replace(" ", " ") # noqa: RUF001 [NO-BREAK SPACE]
description += "\n"
return description.strip()


Expand Down
33 changes: 33 additions & 0 deletions tools/schemapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
import urllib
from typing import Any, Final, Iterable, TYPE_CHECKING, Iterator, Sequence
from operator import itemgetter
from html import unescape

import mistune
from mistune.renderers.rst import RSTRenderer as _RSTRenderer

from tools.schemapi.schemapi import _resolve_references as resolve_references

if TYPE_CHECKING:
from mistune import BlockState
from typing_extensions import LiteralString
from pathlib import Path

Expand Down Expand Up @@ -652,6 +658,33 @@ def is_union_enum(self) -> bool:
return self.is_union() and all(el.is_enum() for el in self.anyOf)


class RSTRenderer(_RSTRenderer):
def __init__(self) -> None:
super().__init__()

def inline_html(self, token: dict[str, Any], state: BlockState) -> str:
html = token["raw"]
return rf"\ :raw-html:`{html}`\ "


class RSTParse(mistune.Markdown):
def __init__(
self,
renderer: mistune.BaseRenderer,
block: mistune.BlockParser | None = None,
inline: mistune.InlineParser | None = None,
plugins=None,
) -> None:
super().__init__(renderer, block, inline, plugins)

def __call__(self, s: str) -> str:
s = super().__call__(s)
return unescape(s).replace(r"\ ,", ",").replace(r"\ ", " ")


rst_parse: RSTParse = RSTParse(RSTRenderer())


def indent_docstring(
lines: list[str], indent_level: int, width: int = 100, lstrip=True
) -> str:
Expand Down

0 comments on commit 170ba3b

Please sign in to comment.