From 4932929dcdab5bc6c9f3a99d47dc45f5cfdf8d39 Mon Sep 17 00:00:00 2001 From: Christopher Davis <82750240+ChristopherDavisUCI@users.noreply.github.com> Date: Thu, 5 Jan 2023 07:20:19 -0600 Subject: [PATCH] Add aliases for ImputeParams and TitleParams (#2732) * Aliases for ImputeParams and TitleParams Let's not merge this for a little while to make sure this doesn't break anything and to think about whether we need to do anything more sophisticated. The point is to make it easier for `impute` and `title` to find the appropriate docstrings, as discussed in https://github.com/altair-viz/altair/pull/2592 * Update altair/vegalite/v5/api.py Co-authored-by: Joel Ostblom * Remove StackOffset alias * Add a test related to aliases Trying to ensure that we are not overwriting something defined on the Vega-Lite side when we define `Bin`, `Impute`, and `Title` in Altair. * Update tests/vegalite/v5/tests/test_alias.py Co-authored-by: Joel Ostblom * Update tests/vegalite/v5/tests/test_alias.py Co-authored-by: Mattijn van Hoek Co-authored-by: Joel Ostblom Co-authored-by: Mattijn van Hoek --- altair/vegalite/v5/api.py | 2 ++ tests/vegalite/v5/tests/test_alias.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/vegalite/v5/tests/test_alias.py diff --git a/altair/vegalite/v5/api.py b/altair/vegalite/v5/api.py index f32ccd631..84a8018d9 100644 --- a/altair/vegalite/v5/api.py +++ b/altair/vegalite/v5/api.py @@ -107,6 +107,8 @@ def _prepare_data(data, context=None): # ------------------------------------------------------------------------ # Aliases & specializations Bin = core.BinParams +Impute = core.ImputeParams +Title = core.TitleParams @utils.use_signature(core.LookupData) diff --git a/tests/vegalite/v5/tests/test_alias.py b/tests/vegalite/v5/tests/test_alias.py new file mode 100644 index 000000000..b9051f13a --- /dev/null +++ b/tests/vegalite/v5/tests/test_alias.py @@ -0,0 +1,21 @@ +import pytest + +import altair.vegalite.v5 as alt + + +def test_aliases(): + """Ensure that any aliases defined in `api.py` aren't colliding with names already defined in `core.py` or `channels.py`.""" + for alias in ["Bin", "Impute", "Title"]: + # this test pass if the alias can resolve to its real name + try: + getattr(alt, alias) + except AttributeError as e: + assert False, f"cannot resolve '{alias}':, {e}" + + # this test fails if the alias match a colliding name in core + with pytest.raises(AttributeError): + getattr(alt.core, alias) + + # this test fails if the alias match a colliding name in channels + with pytest.raises(AttributeError): + getattr(alt.channels, alias)