Skip to content

Commit 0a569e6

Browse files
alexbarrosaquemy
authored andcommitted
fix: time index and gap analysis bugs (#1421)
* fix: scaled plot tab not scaling * fix: reduce dpi for the timeindex to save space * fix: remove period duplicated information * fix: remove duplicated freq info * fix: time index legend * fix: add tolerance to gap identification
1 parent a5d26d5 commit 0a569e6

4 files changed

Lines changed: 32 additions & 41 deletions

File tree

src/ydata_profiling/model/pandas/describe_timeseries_pandas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def compute_gap_stats(series: pd.Series) -> pd.Series:
166166
base_frequency = 1
167167

168168
diff = gap.diff()
169-
anchors = gap[diff > period].index
169+
anchors = gap[diff > 2 * period].index
170170
gaps = []
171171
for i in anchors:
172172
gaps.append(gap.loc[gap.index[[i - 1, i]]].values)

src/ydata_profiling/report/structure/overview.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,13 @@ def format_tsindex_limit(limit: Any) -> str:
312312

313313
ts_info = Table(table_stats, name="Timeseries statistics", style=config.html.style)
314314

315+
dpi_bak = config.plot.dpi
316+
config.plot.dpi = 300
315317
timeseries = ImageWidget(
316318
plot_overview_timeseries(config, summary.variables),
317319
image_format=config.plot.image_format,
318320
alt="ts_plot",
319-
name="preview",
321+
name="original",
320322
anchor_id="ts_plot_overview",
321323
)
322324
timeseries_scaled = ImageWidget(
@@ -326,6 +328,7 @@ def format_tsindex_limit(limit: Any) -> str:
326328
name="scaled",
327329
anchor_id="ts_plot_scaled_overview",
328330
)
331+
config.plot.dpi = dpi_bak
329332
ts_tab = Container(
330333
[timeseries, timeseries_scaled],
331334
anchor_id="ts_plot_overview",

src/ydata_profiling/report/structure/variables/render_timeseries.py

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,47 +25,31 @@
2525
def _render_gap_tab(config: Settings, summary: dict) -> Container:
2626
gap_stats = [
2727
{
28-
"name": "period",
28+
"name": "min inverval",
2929
"value": fmt_numeric(
30-
summary["gap_stats"]["period"], precision=config.report.precision
30+
summary["gap_stats"]["min"], precision=config.report.precision
31+
),
32+
},
33+
{
34+
"name": "max inverval",
35+
"value": fmt_numeric(
36+
summary["gap_stats"]["max"], precision=config.report.precision
37+
),
38+
},
39+
{
40+
"name": "mean inverval",
41+
"value": fmt_numeric(
42+
summary["gap_stats"]["mean"], precision=config.report.precision
43+
),
44+
},
45+
{
46+
"name": "interval std",
47+
"value": fmt_numeric(
48+
summary["gap_stats"]["std"], precision=config.report.precision
3149
),
3250
},
3351
]
34-
if "frequency" in summary["gap_stats"]:
35-
gap_stats.append(
36-
{
37-
"name": "frequency",
38-
"value": summary["gap_stats"]["frequency"],
39-
}
40-
)
41-
gap_stats.extend(
42-
[
43-
{
44-
"name": "min inverval",
45-
"value": fmt_numeric(
46-
summary["gap_stats"]["min"], precision=config.report.precision
47-
),
48-
},
49-
{
50-
"name": "max inverval",
51-
"value": fmt_numeric(
52-
summary["gap_stats"]["max"], precision=config.report.precision
53-
),
54-
},
55-
{
56-
"name": "mean inverval",
57-
"value": fmt_numeric(
58-
summary["gap_stats"]["mean"], precision=config.report.precision
59-
),
60-
},
61-
{
62-
"name": "interval std",
63-
"value": fmt_numeric(
64-
summary["gap_stats"]["std"], precision=config.report.precision
65-
),
66-
},
67-
]
68-
)
52+
6953
gap_table = Table(
7054
gap_stats,
7155
name="Intervals statistics",

src/ydata_profiling/visualisation/plot.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,13 @@ def plot_overview_timeseries(
640640
else:
641641
for col, data in variables.items():
642642
if data["type"] == "TimeSeries":
643-
data["series"].plot(ax=ax, label=col)
643+
series = data["series"]
644+
if scale:
645+
series = (series - series.min()) / (series.max() - series.min())
646+
series.plot(ax=ax, label=col, alpha=0.65)
644647

645-
plt.legend(loc="upper right")
648+
plt.legend(bbox_to_anchor=(1.04, 1), loc="upper left")
649+
plt.subplots_adjust(right=0.7)
646650
return plot_360_n0sc0pe(config)
647651

648652

0 commit comments

Comments
 (0)