Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create aliases for all *Params classes? #2903

Open
mattijn opened this issue Feb 19, 2023 · 5 comments
Open

Create aliases for all *Params classes? #2903

mattijn opened this issue Feb 19, 2023 · 5 comments
Labels
breaking Requires a **MAJOR** version bump

Comments

@mattijn
Copy link
Contributor

mattijn commented Feb 19, 2023

As was originally posted by @mattijn in #2732 (comment):

There are more candidate aliases I think?

import requests as r
import re
vl_scheme = r.get('https://vega.github.io/schema/vega-lite/v5.json').json()
scheme_str = str(vl_scheme['definitions'])
col = []
for word in re.findall(r"\w+", scheme_str):
    if 'Params' in word:
        col.append(word)
list(set(col))

Returns 10 candidates:

['TimeUnitParams',
 'TitleParams',
 'SchemeParams',
 'GraticuleParams',
 'SequenceParams',
 'BinParams',
 'ImputeParams',
 'ScaleBinParams',
 'ScaleInterpolateParams',
 'AutoSizeParams']

I think we can extend the aliases to all of these. I was trying:

alt.Color('value:Q').scale(scheme=alt.Scheme('viridis'))

But hit an:

AttributeError: module 'altair' has no attribute 'Scheme'
@ChristopherDavisUCI
Copy link
Contributor

Hi @mattijn, that sounds fine to me. The reason I proposed aliases for some of these like BinParams but not others was just for symmetry with the Property Setters. For example, I believe there is a bin Property Setter, but not a scheme Property Setter. No other opinion on my end, just wanted to record this.

@mattijn
Copy link
Contributor Author

mattijn commented Feb 19, 2023

Thanks for the clarification @ChristopherDavisUCI, that make sense for #2732. The remaining properties are indeed not available as Property Setter, but it is still useful to have an alias I think.

@joelostblom
Copy link
Contributor

In addition to what @ChristopherDavisUCI mentioned, I think it does make sense to include alias for the classes that we expect users to directly interface with (and maybe hiding the *Params version from tab completion for those that have shortcuts?). For example, do we need aliases for 'GraticuleParams', 'SequenceParams', since there is already alt.sequence and alt.graticule?

@joelostblom
Copy link
Contributor

Maybe we should also consider adding shortcuts for some of the *Config classes? Maybe not as important but I just learned in #3216 (comment) that we can do something like

alt.Chart(iris, view=alt.ViewConfig(strokeWidth=0))

Which might seem inconsistent with that if we modify say the height we can use alt.Step instead of alt.StepConfig

alt.Chart(iris, height=alt.Step(40))

So I wonder if it should also be called just alt.View. However, there are a lot of these config options, so maybe there is a chance of name collisions with other objects and maybe Config is fundamentally something different so it makes sense to be explicit in the name?

import requests as r
import re
vl_scheme = r.get('https://vega.github.io/schema/vega-lite/v5.json').json()
scheme_str = str(vl_scheme['definitions'])
col = []
for word in re.findall(r"\w+", scheme_str):
    if 'Config' in word:
        col.append(word)
list(set(col))
['RectConfig',
 'ProjectionConfig',
 'BarConfig',
 'LegendConfig',
 'AreaConfig',
 'PointSelectionConfig',
 'AnyMarkConfig',
 'MarkConfig',
 'HeaderConfig',
 'ScaleConfig',
 'ErrorBarConfig',
 'BrushConfig',
 'BoxPlotConfig',
 'TitleConfig',
 'PointSelectionConfigWithoutType',
 'IntervalSelectionConfigWithoutType',
 'Config',
 'CompositionConfig',
 'SelectionConfig',
 'LineConfig',
 'AxisConfig',
 'ErrorBandConfig',
 'FormatConfig',
 'TickConfig',
 'StyleConfigIndex',
 'IntervalSelectionConfig',
 'RangeConfig',
 'ViewConfig']

@dangotbanned
Copy link
Member

I'm linking #2918 because this won't be possible right now without causing collisions in the top level namespace

I had thought about this in other PRs though

@dangotbanned dangotbanned changed the title Create aliases for all (*Params) classes? Create aliases for all *Params classes? Jan 7, 2025
@dangotbanned dangotbanned added the breaking Requires a **MAJOR** version bump label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Requires a **MAJOR** version bump
Projects
None yet
Development

No branches or pull requests

4 participants