From c8db456d9d6423184c602b48de131cd2b94fe884 Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Tue, 29 Nov 2022 20:20:05 -0800 Subject: [PATCH 1/6] 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 --- altair/vegalite/v5/api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/altair/vegalite/v5/api.py b/altair/vegalite/v5/api.py index 468aac790..04ac028b1 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) From 8e9a79e274262df983db436c0ee1fe539598c38a Mon Sep 17 00:00:00 2001 From: Christopher Davis <82750240+ChristopherDavisUCI@users.noreply.github.com> Date: Tue, 3 Jan 2023 14:32:02 -0600 Subject: [PATCH 2/6] Update altair/vegalite/v5/api.py Co-authored-by: Joel Ostblom --- altair/vegalite/v5/api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/altair/vegalite/v5/api.py b/altair/vegalite/v5/api.py index 84a8018d9..efac11d7a 100644 --- a/altair/vegalite/v5/api.py +++ b/altair/vegalite/v5/api.py @@ -109,6 +109,7 @@ def _prepare_data(data, context=None): Bin = core.BinParams Impute = core.ImputeParams Title = core.TitleParams +Stack = core.StackOffset @utils.use_signature(core.LookupData) From 7535c02b08ff26d3834ae99cda70c39c96e76217 Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Wed, 4 Jan 2023 06:34:04 -0600 Subject: [PATCH 3/6] Remove StackOffset alias --- altair/vegalite/v5/api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/altair/vegalite/v5/api.py b/altair/vegalite/v5/api.py index efac11d7a..84a8018d9 100644 --- a/altair/vegalite/v5/api.py +++ b/altair/vegalite/v5/api.py @@ -109,7 +109,6 @@ def _prepare_data(data, context=None): Bin = core.BinParams Impute = core.ImputeParams Title = core.TitleParams -Stack = core.StackOffset @utils.use_signature(core.LookupData) From 36bb2f98b29c74264431787cea3173978c6404ac Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Wed, 4 Jan 2023 07:18:00 -0600 Subject: [PATCH 4/6] 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. --- tests/vegalite/v5/tests/test_alias.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/vegalite/v5/tests/test_alias.py diff --git a/tests/vegalite/v5/tests/test_alias.py b/tests/vegalite/v5/tests/test_alias.py new file mode 100644 index 000000000..e4c49f9ca --- /dev/null +++ b/tests/vegalite/v5/tests/test_alias.py @@ -0,0 +1,15 @@ +import pytest + +import altair.vegalite.v5 as alt + + +def test_aliases(): + """We define `Bin` to be an alias `BinParams`, and similarly `Impute` for `ImputeParams` and `Title` for `TitleParams`. Here we ensure that `Bin`, `Impute`, and `Title` are not already defined in `core.py` or `channels.py`.""" + for alias in ["Bin", "Impute", "Title"]: + getattr(alt, alias) + + with pytest.raises(AttributeError): + getattr(alt.core, alias) + + with pytest.raises(AttributeError): + getattr(alt.channels, alias) From 8e37ff3593f8a29eeea463297a11ee6fb14617f5 Mon Sep 17 00:00:00 2001 From: Christopher Davis <82750240+ChristopherDavisUCI@users.noreply.github.com> Date: Wed, 4 Jan 2023 07:50:40 -0600 Subject: [PATCH 5/6] Update tests/vegalite/v5/tests/test_alias.py Co-authored-by: Joel Ostblom --- tests/vegalite/v5/tests/test_alias.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/vegalite/v5/tests/test_alias.py b/tests/vegalite/v5/tests/test_alias.py index e4c49f9ca..93c24426e 100644 --- a/tests/vegalite/v5/tests/test_alias.py +++ b/tests/vegalite/v5/tests/test_alias.py @@ -4,7 +4,7 @@ def test_aliases(): - """We define `Bin` to be an alias `BinParams`, and similarly `Impute` for `ImputeParams` and `Title` for `TitleParams`. Here we ensure that `Bin`, `Impute`, and `Title` are not already defined in `core.py` or `channels.py`.""" + """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"]: getattr(alt, alias) From 62c02eb36c8735b8447c9e648ad527c4ecbfc96a Mon Sep 17 00:00:00 2001 From: Christopher Davis <82750240+ChristopherDavisUCI@users.noreply.github.com> Date: Wed, 4 Jan 2023 09:35:19 -0600 Subject: [PATCH 6/6] Update tests/vegalite/v5/tests/test_alias.py Co-authored-by: Mattijn van Hoek --- tests/vegalite/v5/tests/test_alias.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/vegalite/v5/tests/test_alias.py b/tests/vegalite/v5/tests/test_alias.py index 93c24426e..b9051f13a 100644 --- a/tests/vegalite/v5/tests/test_alias.py +++ b/tests/vegalite/v5/tests/test_alias.py @@ -6,10 +6,16 @@ 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"]: - getattr(alt, alias) + # 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)