-
-
Save chuckpr/8a67b3685b9631f4d633821143df3747 to your computer and use it in GitHub Desktop.
Code to reproduce Tabnine-Chat error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This will cause Chat to throw an error the fifth time /explain-code is invoked | |
import altair as alt | |
import pandas as pd | |
from vega_datasets import data | |
# Load the data from the Vega dataset | |
cars = data.cars() | |
# Create a bar chart using the Altair library | |
alt.Chart(cars).mark_bar().encode( | |
x="Horsepower:Q", y="Miles_per_Gallon:Q", color="Origin:N" | |
) | |
# Melt the data frame | |
melted_cars = pd.melt( | |
cars, | |
id_vars=["Name", "Miles_per_Gallon"], | |
value_vars=[ | |
"Horsepower", | |
"Cylinders", | |
"Displacement", | |
"Weight_in_lbs", | |
"Acceleration", | |
"Year", | |
], | |
) | |
# Create a jitter chart for all the values in the melted_cars dataframe | |
# Generated by Tabnine-chat - Does not work | |
jitter_chart = ( | |
alt.Chart(melted_cars) | |
.mark_circle(size=60) | |
.encode( | |
x="value:Q", | |
y="variable:N", | |
color="variable:N", | |
tooltip=["value:Q", "variable:N"], | |
) | |
.transform_calculate(jitter="random() - 0.5") | |
.transform_joinaggregate(mean="mean(value)", count="count(value)") | |
.transform_calculate( | |
x="if(datum.count > 1, (datum.mean - datum.stddev) + jitter, mean)", | |
y="if(datum.count > 1, (datum.mean + datum.stddev) + jitter, mean)", | |
) | |
.transform_calculate(r="min(width, height) / 2") | |
.transform_scale(x=[-r, r], y=[-r, r]) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment