-
Notifications
You must be signed in to change notification settings - Fork 794
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: FacetedEncoding.init() got multiple values for argument 'self' #3634
Comments
@gaspardc-met could you provide the traceback please? I'm unsure what Reproimport altair as alt
>>> alt.FacetedEncoding().init() TracebackAttributeError Traceback (most recent call last)
Cell In[17], line 3
1 import altair as alt
----> 3 alt.FacetedEncoding().init()
File c:/../altair/altair/utils/schemapi.py:1063, in SchemaBase.__getattr__(self, attr)
1061 except AttributeError:
1062 _getattr = super().__getattribute__
-> 1063 return _getattr(attr)
AttributeError: 'FacetedEncoding' object has no attribute 'init' |
Hey @dangotbanned , Sorry I clipped some of the error, it was the
|
Removing streamlit caching on the plotting function (
|
Thanks for the additional traceback. IssuesI'm trying to piece together all the issues you've raised related to
As you've seen in comment, removing Versions
From this I can only conclude that #3444 is probably unrelated, since that was introduced in Looking at the previous functionality - you can see that this code has not changed in a meaningful way in any Possible FixAs you have not provided a reproducible example, I can only guess what might be the cause. It could be possible that Reading PEP 667, made me think the use of I'm able to make the change below without causing a regression in versions we currently support (
|
Hi @dangotbanned , Thank you for your incredibly detailed feedback. The issue is not between altair and streamlit, but between altair and pyinstrument that I use to profile the app loading time. This solves both # altair_repro.py
import altair as alt
import numpy as np
import pandas as pd
from pyinstrument import Profiler
def plot_chart():
start = pd.date_range(start="2022-01-01", periods=48, freq="30min")
data = pd.DataFrame(
{
"machine": np.random.choice(["A", "B", "C"], 48), # noqa: NPY002
"load": np.random.rand(48), # noqa: NPY002
"start_time": start,
"end_time": start + pd.Timedelta("60min"),
}
)
chart = (
alt.Chart(data)
.mark_bar()
.encode(
x=alt.X("start_time:T", title=""),
x2=alt.X2("end_time:T", title=""),
y=alt.Y("machine:N", title=""),
strokeWidth=alt.value(2),
)
)
chart.display()
if __name__ == "__main__":
with Profiler() as profiler:
plot_chart() Thank you for your valuable time and patience. note: this does not fix this issue streamlit/streamlit#9616 |
Just realized the bug doesn't seem to show up on python 3.10. Steps to reproduce (on my side at least):
|
@gaspardc-met thanks for #3634 (comment), really helpful in narrowing things down
@gaspardc-met what version of v4.7.3 may fix the issue and would explain the difference with Another thing to test would be reducing the change in comment-Possible Fix to just Using a |
I used the latest pyinstrument on all python versions for the repro
Good thing to note that that "just" setting |
Great thanks @gaspardc-met One last alternative I wanna check before figuring out a repro using only:
|
dev = [ | |
"hatch", | |
"ruff>=0.6.0", | |
"ibis-framework[polars]", | |
"ipython[kernel]", | |
"pandas>=0.25.3", | |
"pytest", | |
"pytest-cov", | |
"pytest-xdist[psutil]~=3.5", | |
"mistune", | |
"mypy", | |
"pandas-stubs", | |
"types-jsonschema", | |
"types-setuptools", | |
"geopandas", | |
"polars>=0.20.3", | |
] |
I can add this in the generated code, which removes the need for using locals()
entirely.
I'd prefer this since it is less "magic" and in theory should have the same semantics for all versions.
Does this work on 3.12
?
diff --git a/altair/vegalite/v5/schema/channels.py b/altair/vegalite/v5/schema/channels.py
index c978330a..9972a54e 100644
--- a/altair/vegalite/v5/schema/channels.py
+++ b/altair/vegalite/v5/schema/channels.py
@@ -25257,9 +25257,48 @@ class _EncodingMixin:
Offset of y-position of the marks
"""
# Compat prep for `infer_encoding_types` signature
- kwargs = locals()
- kwargs.pop("self")
- args = kwargs.pop("args")
+ kwargs = dict( # noqa: C408
+ angle=angle,
+ color=color,
+ column=column,
+ description=description,
+ detail=detail,
+ facet=facet,
+ fill=fill,
+ fillOpacity=fillOpacity,
+ href=href,
+ key=key,
+ latitude=latitude,
+ latitude2=latitude2,
+ longitude=longitude,
+ longitude2=longitude2,
+ opacity=opacity,
+ order=order,
+ radius=radius,
+ radius2=radius2,
+ row=row,
+ shape=shape,
+ size=size,
+ stroke=stroke,
+ strokeDash=strokeDash,
+ strokeOpacity=strokeOpacity,
+ strokeWidth=strokeWidth,
+ text=text,
+ theta=theta,
+ theta2=theta2,
+ tooltip=tooltip,
+ url=url,
+ x=x,
+ x2=x2,
+ xError=xError,
+ xError2=xError2,
+ xOffset=xOffset,
+ y=y,
+ y2=y2,
+ yError=yError,
+ yError2=yError2,
+ yOffset=yOffset,
+ )
if args:
kwargs = {k: v for k, v in kwargs.items() if v is not Undefined}
Works like a charm (tested with 3.11 and 3.12) 👍 EDIT: so you have to repro the bug without pyinstrument ? So just "manually" messing with the locals ? |
Perfect
@gaspardc-met ideally I'd like to add a test to the
It is definitely helpful knowing For example, if I will say though that I'm personally fine with simply pushing the fix alone. @mattijn @jonmmease does this sound reasonable to you? |
What happened?
Using a complex altair chart in streamlit, worked in 5.3.0, and broke with 5.4.0 and then 5.4.1.
It seems to be an altair issue:
TypeError: FacetedEncoding.init() got multiple values for argument 'self'
I tried to reproduce the error with the plot code and anonymized example data.
The error didn't show up neither with altair alone nor streamlit+altair.
However, it might give you an idea of the plot I use. The error happens in the first call to
.encode
in the fonction.mark_bar.encode()
Long Code Block
What would you like to happen instead?
No response
Which version of Altair are you using?
altair: 5.4.1
python: 3.11
The text was updated successfully, but these errors were encountered: