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

TypeError: 'GetAttrExpression' object is not callable with interval.ref() #3059

Closed
ghost opened this issue May 17, 2023 · 5 comments · Fixed by #3063
Closed

TypeError: 'GetAttrExpression' object is not callable with interval.ref() #3059

ghost opened this issue May 17, 2023 · 5 comments · Fixed by #3063
Labels

Comments

@ghost
Copy link

ghost commented May 17, 2023

Thanks for the wonderful library!

Using the previous version 4.2.2, everything works fine, but with 5.0.0, the following code produces the error shown:

interval = alt.selection_interval(encodings=["x"])
interval.ref()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[10], line 2
      1 interval = alt.selection_interval(encodings=["x"])
----> 2 interval.ref()

TypeError: 'GetAttrExpression' object is not callable
@ghost ghost added the bug label May 17, 2023
@mattijn
Copy link
Contributor

mattijn commented May 17, 2023

Thanks for the report @tkyoma!

In Altair version 4.2.2 the .ref() did return a dictionary, but from Altair version 5 the alt.selection_interval() returns a Parameter object and not a Selection object.

Can you elaborate a little bit more in what way you are using this syntax? I'm not yet sure if this a bug or a breaking change. Would it for example be possible to use interval.to_dict() instead?

@EtienneT
Copy link

I got the exact same problem today.

I installed altair 5.0.0, coded some graphs, then installed streamlit which requires altair 4. I later realized that the code was not working anymore and uninstalled streamlit and reinstalled altair 5, but the .ref() error was still occurring even though I restarted my notebook kernel, restarted jupyter to make sure I was using the latest version. alt.version returns 5.0.0 too.

I can reproduce the problem by using this example from the docs:

import altair as alt
from vega_datasets import data

weather = data.seattle_weather()

interval = alt.selection_interval(encodings=['x'])

base = alt.Chart(weather).mark_rule(size=2).encode(
    x='date:T',
    y='temp_min:Q',
    y2='temp_max:Q',
    color='weather:N'
)

chart = base.encode(
    x=alt.X('date:T', scale=alt.Scale(domain=interval.ref()))
).properties(
    width=800,
    height=300
)

view = base.add_selection(
    interval
).properties(
    width=800,
    height=50,
)

chart & view

I am getting the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [1], in <cell line: 15>()
      6 interval = alt.selection_interval(encodings=['x'])
      8 base = alt.Chart(weather).mark_rule(size=2).encode(
      9     x='date:T',
     10     y='temp_min:Q',
     11     y2='temp_max:Q',
     12     color='weather:N'
     13 )
     15 chart = base.encode(
---> 16     x=alt.X('date:T', scale=alt.Scale(domain=interval.ref()))
     17 ).properties(
     18     width=800,
     19     height=300
     20 )
     22 view = base.add_selection(
     23     interval
     24 ).properties(
     25     width=800,
     26     height=50,
     27 )
     29 chart & view

TypeError: 'GetAttrExpression' object is not callable

@joelostblom
Copy link
Contributor

@EtienneT Does your example work if you remove the .ref part and just use domain=interval? And could you give a link to the where in the docs that example is so that we can update it?

@EtienneT
Copy link

Here is the documentation link:
https://altair-viz.github.io/altair-tutorial/notebooks/06-Selections.html#binding-scales-to-other-domains

On my main conda environment, if I remove the call to .ref(), I get the following error:

C:\Users\etrem\anaconda3\envs\fastai\lib\site-packages\altair\utils\deprecation.py:65: AltairDeprecationWarning: 'add_selection' is deprecated. Use 'add_params' instead.
  warnings.warn(message, AltairDeprecationWarning, stacklevel=1)
Javascript Error: e.map is not a function
This usually means there's a typo in your chart specification. See the javascript console for the full traceback.

Even though I am using version 5.0.0.

But then I created a completely fresh environment, tried it without the .ref() call and it works. Something got corrupted in my current environment.

@EtienneT
Copy link

Can we do the same x-axis selection in altair 4 (to work in streamlit) which changes the scale of the X axis?

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants