-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
Histogram chart not able to use decimal datatype column #30301
Comments
I found a similar closed issue that might be relevant to your problem: [Table Viz] "unsupported operant type errors" in percentage metrics [1]. The error "The column 'start_rate' must be numeric" occurs because the Histogram chart in Superset requires the specified column to be numeric. The To ensure that the Here is the relevant part of the def histogram(
df: DataFrame,
column: str,
groupby: list[str] | None,
bins: int = 5,
cumulative: bool = False,
normalize: bool = False,
) -> DataFrame:
"""
Generate a histogram DataFrame from a given DataFrame.
Parameters:
df (DataFrame): The input DataFrame.
column (str): The column of the DataFrame to calculate the histogram on.
groupby (list[str]): The columns to group by. If empty, no grouping is performed.
bins (int): The number of bins to use for the histogram. Default is 5.
cumulative (bool): Whether to calculate a cumulative histogram. Default is False.
normalize (bool): Whether to normalize the histogram. Default is False.
Returns:
DataFrame: A DataFrame where each row corresponds to a group (or the entire DataFrame if no grouping is performed),
and each column corresponds to a histogram bin. The values are the counts in each bin.
"""
if groupby is None:
groupby = []
# check if the column is numeric
if not np.issubdtype(df[column].dtype, np.number):
raise ValueError(f"The column '{column}' must be numeric.") Ensure that the |
Even if the columns are correctly set to numeric datatypes in the database, Superset still doesn't interpret this properly (converts to One way around this is to convert/cast the column to Hopefully this can be solved on Superset's end, but otherwise I hope it helps with your problem for now :) |
@BlakeList This worked, thanks for that tip! Though it seems it surfaced a new issue in that the histogram chart only creates bin delineations at whole integer numbers and doesn't play nicely when a lot of the values are <1 e.g. 0.33) |
Bug description
When I try to create a Histogram chart and choose a decimal datatype column (e.g.
start_rate
in my scenario)as the main column, I get an error that says:But I have checked that it is a decimal datatype (Postgres db) which is equivalent to the
numeric
datatype.How to reproduce the bug
What I expect: histogram is created
What actually happens: I get the following error:
Screenshots/recordings
Superset version
master / latest-dev
Python version
I don't know
Node version
I don't know
Browser
Chrome
Additional context
No response
Checklist
The text was updated successfully, but these errors were encountered: