Jupyter Notebook用TQDM的progress_apply触发FutureWarning如何解决
告警原因说明
该告警由低版本tqdm的pandas兼容逻辑触发:你当前使用的tqdm版本为了兼容pandas早期版本,会调用pandas顶层命名空间中的Panel类,而Panel数据结构早已在pandas 1.0+版本中正式移除,因此触发了FutureWarning。该告警暂时不影响现有progress_apply功能运行,但后续pandas版本升级后可能导致功能完全失效。
解决方案
方案1:升级tqdm到最新正式版(首选)
该bug已在tqdm 4.49.0及后续版本中官方修复,升级后原有代码无需任何修改即可消除告警,同时保障后续版本兼容性:
- 使用pip升级:
pip install --upgrade tqdm
- 使用conda升级:
conda update -c conda-forge tqdm
方案2:临时屏蔽特定告警(仅适用于无法升级tqdm的场景)
如果受环境限制暂时无法升级tqdm,可以通过warnings模块精准过滤该类告警,不影响其他告警的正常提示:
import warnings from pandas.errors import FutureWarning # 仅过滤Panel类移除相关的FutureWarning warnings.filterwarnings( "ignore", category=FutureWarning, message=".*The Panel class is removed from pandas.*" ) from tqdm.notebook import tqdm tqdm.pandas()
注意:该方案仅为临时规避手段,仍建议尽快升级tqdm版本避免后续兼容性风险。
内容的提问来源于stack exchange,提问作者Mark Heptonstall
相关产品推荐
相关产品推荐

