Skip to content

Commit

Permalink
Add aliases for ImputeParams and TitleParams (#2732)
Browse files Browse the repository at this point in the history
* 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 #2592

* Update altair/vegalite/v5/api.py

Co-authored-by: Joel Ostblom <joelostblom@users.noreply.github.com>

* 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 <joelostblom@users.noreply.github.com>

* Update tests/vegalite/v5/tests/test_alias.py

Co-authored-by: Mattijn van Hoek <mattijn@gmail.com>

Co-authored-by: Joel Ostblom <joelostblom@users.noreply.github.com>
Co-authored-by: Mattijn van Hoek <mattijn@gmail.com>
  • Loading branch information
3 people committed Jan 5, 2023
1 parent b1774e6 commit 4932929
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions tests/vegalite/v5/tests/test_alias.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 4932929

Please sign in to comment.