You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用ydata-profiling保存HTML报告遇MatplotlibDeprecationWarning求助

解决ydata-profiling与matplotlib版本兼容的警告问题

问题根源

ydata-profiling v4.5.1的context.py第85行仍在使用matplotlib 3.7.3已弃用的mplDeprecation,而非官方指定的MatplotlibDeprecationWarning,导致触发警告。常规warnings.filterwarnings无效是因为警告在库内部的处理逻辑中被重新触发,普通过滤规则未覆盖到。

解决方案

1. 升级ydata-profiling(推荐)

后续版本(如v4.6.0及以上)已修复该兼容问题,直接执行升级命令即可:

pip install --upgrade ydata-profiling

2. 精准拦截警告(无法升级时使用)

在代码最开头设置针对性的警告过滤器,确保在导入ydata-profiling前生效:

import warnings
from matplotlib import MatplotlibDeprecationWarning

# 过滤来自ydata_profiling.context模块的MatplotlibDeprecationWarning
warnings.filterwarnings("ignore", category=MatplotlibDeprecationWarning, module="ydata_profiling.context")

# 后续正常导入并生成报告
import pandas as pd
from ydata_profiling import ProfileReport

df = pd.DataFrame({"col1": [1,2,3], "col2": [4,5,6]})
report = ProfileReport(df)
report.to_file("output_report.html")

3. 临时修改源码(不推荐)

找到Python环境中ydata_profiling/context.py文件的第85行,将mplDeprecation替换为matplotlib.MatplotlibDeprecationWarning。此方法仅作临时应急,后续升级库会覆盖修改,不建议长期使用。

内容的提问来源于stack exchange,提问作者Jana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 02:23:14