Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomedina248 committed Jun 2, 2022
1 parent bf99d93 commit d46bd78
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion superset/utils/pandas_postprocessing/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def outliers(series: Series) -> Set[float]:

# nanpercentile needs numeric values, otherwise the isnan function
# that's used in the underlying function will fail
for column in df:
for column in metrics:
if df.dtypes[column] == np.object:
df[column] = to_numeric(df[column], errors="coerce")

Expand Down
25 changes: 25 additions & 0 deletions tests/unit_tests/pandas_postprocessing/test_boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,28 @@ def test_boxplot_percentile_incorrect_params():
metrics=["cars"],
percentiles=[10, 90, 10],
)


def test_boxplot_type_coercion():
df = names_df
df["cars"] = df["cars"].astype(str)
df = boxplot(
df=df,
groupby=["region"],
whisker_type=PostProcessingBoxplotWhiskerType.TUKEY,
metrics=["cars"],
)

columns = {column for column in df.columns}
assert columns == {
"cars__mean",
"cars__median",
"cars__q1",
"cars__q3",
"cars__max",
"cars__min",
"cars__count",
"cars__outliers",
"region",
}
assert len(df) == 4

0 comments on commit d46bd78

Please sign in to comment.