fix: drop NaN timestamps, use facecolor to suppress matplotlib warning
This commit is contained in:
@@ -41,6 +41,15 @@ def read_csv(path: str | Path, value_col: str = "value") -> tuple[list[int], lis
|
|||||||
|
|
||||||
fixed = raw_strs.apply(_fix_hour60)
|
fixed = raw_strs.apply(_fix_hour60)
|
||||||
timestamps.loc[na_mask] = pd.to_datetime(fixed, errors="coerce")
|
timestamps.loc[na_mask] = pd.to_datetime(fixed, errors="coerce")
|
||||||
|
# 丢弃时间戳仍为 NaN 的行(coerce 后无法恢复的异常时间戳)
|
||||||
|
valid_mask = timestamps.notna()
|
||||||
|
if not valid_mask.all():
|
||||||
|
n_drop = (~valid_mask).sum()
|
||||||
|
import logging
|
||||||
|
logging.getLogger(__name__).warning("dropping %d rows with invalid timestamps", n_drop)
|
||||||
|
timestamps = timestamps[valid_mask].reset_index(drop=True)
|
||||||
|
df = df[valid_mask].reset_index(drop=True)
|
||||||
|
|
||||||
timestamps_ms = (timestamps.astype("int64") // 10**6).tolist()
|
timestamps_ms = (timestamps.astype("int64") // 10**6).tolist()
|
||||||
|
|
||||||
values = df[value_col].astype(float).tolist()
|
values = df[value_col].astype(float).tolist()
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ def render_column(
|
|||||||
ax.plot(hours, values, color="#333333", linewidth=0.8, alpha=0.9)
|
ax.plot(hours, values, color="#333333", linewidth=0.8, alpha=0.9)
|
||||||
if has_gt:
|
if has_gt:
|
||||||
for start_h, end_h in gt_windows_h:
|
for start_h, end_h in gt_windows_h:
|
||||||
ax.axvspan(start_h, end_h, alpha=0.35, color="#FF4444",
|
ax.axvspan(start_h, end_h, alpha=0.35, facecolor="#FF4444",
|
||||||
edgecolor="#CC0000", linewidth=1.5)
|
edgecolor="#CC0000", linewidth=1.5)
|
||||||
# 异常点散点标记
|
# 异常点散点标记
|
||||||
anom_hours = [hours[i] for i, l in enumerate(gt_labels) if l == 1]
|
anom_hours = [hours[i] for i, l in enumerate(gt_labels) if l == 1]
|
||||||
@@ -326,7 +326,7 @@ def render_column(
|
|||||||
for wstart, wend in windows:
|
for wstart, wend in windows:
|
||||||
ws_h = (wstart - t0) / 3_600_000
|
ws_h = (wstart - t0) / 3_600_000
|
||||||
we_h = (wend - t0) / 3_600_000
|
we_h = (wend - t0) / 3_600_000
|
||||||
ax.axvspan(ws_h, we_h, alpha=0.4, color=color,
|
ax.axvspan(ws_h, we_h, alpha=0.4, facecolor=color,
|
||||||
edgecolor=color, linewidth=1.5)
|
edgecolor=color, linewidth=1.5)
|
||||||
det_hours_list.append((ws_h, we_h))
|
det_hours_list.append((ws_h, we_h))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user