Skip to content

Commit 271c04f

Browse files
Transform additionnal plots
1 parent 7611397 commit 271c04f

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

shapash/plots/plot_univariate.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ def plot_continuous_distribution(
165165
else:
166166
style_dict = define_style(get_palette(palette_name))
167167

168-
lower_quantile = df_all[col].quantile(0.005)
169-
upper_quantile = df_all[col].quantile(0.995)
170-
filtered_data = df_all[(df_all[col] > lower_quantile) & (df_all[col] < upper_quantile)].copy()
168+
filtered_data = df_all.copy()
169+
if len(filtered_data) > 200:
170+
lower_quantile = filtered_data[col].quantile(0.005)
171+
upper_quantile = filtered_data[col].quantile(0.995)
172+
filtered_data = filtered_data[(filtered_data[col] > lower_quantile) & (filtered_data[col] < upper_quantile)]
171173

172174
# Initialize the figure
173175
fig = go.Figure()

tests/unit_tests/report/test_plots.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import numpy as np
55
import pandas as pd
66

7-
from shapash.report.common import VarType
87
from shapash.plots.plot_univariate import (
98
plot_distribution,
109
plot_categorical_distribution,
@@ -56,7 +55,7 @@ def test_plot_distribution_3(self, mock_plot_cat, mock_plot_cont):
5655
def test_plot_continuous_distribution_1(self):
5756
df = pd.DataFrame(
5857
{
59-
"int_data": [10, 20, 30, 40],
58+
"int_data": [10, 20, 30, 40, 50],
6059
}
6160
)
6261
fig = plot_continuous_distribution(df, "int_data")
@@ -67,8 +66,8 @@ def test_plot_continuous_distribution_1(self):
6766
def test_plot_continuous_distribution_2(self):
6867
df = pd.DataFrame(
6968
{
70-
"int_data": [10, 20, 30, 40, 50, 30, 20, 0],
71-
"data_train_test": ["train", "train", "train", "train", "test", "test", "test", "test"],
69+
"int_data": [10, 20, 30, 40, 50, 30, 20, 0, 10, 20],
70+
"data_train_test": ["train", "train", "train", "train", "train", "test", "test", "test", "test", "test"],
7271
}
7372
)
7473
fig = plot_continuous_distribution(df, "int_data", "data_train_test")

tests/unit_tests/utils/test_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_compute_digit_number_2(self):
6767

6868
def test_compute_digit_number_3(self):
6969
t = compute_digit_number(0.000044)
70-
assert t == 7
70+
assert t == 8
7171

7272
def test_truncate_str_1(self):
7373
t = truncate_str(12)

0 commit comments

Comments
 (0)