我得到以下内容UserWarning
当尝试使用 joblib 缓存结果时:
import numpy
from tempfile import mkdtemp
cachedir = mkdtemp()
from joblib import Memory
memory = Memory(cachedir=cachedir, verbose=0)
@memory.cache
def get_nc_var3d(path_nc, var, year):
"""
Get value from netcdf for variable var for year
:param path_nc:
:param var:
:param year:
:return:
"""
try:
hndl_nc = open_or_die(path_nc)
val = hndl_nc.variables[var][int(year), :, :]
except:
val = numpy.nan
logger.info('Error in getting var ' + var + ' for year ' + str(year) + ' from netcdf ')
hndl_nc.close()
return val
使用参数调用此函数时收到以下警告:
UserWarning: Persisting input arguments took 0.58s to run.
If this happens often in your code, it can cause performance problems
(results will be correct in all cases).
The reason for this is probably some large input arguments for a wrapped function (e.g. large strings).
THIS IS A JOBLIB ISSUE. If you can, kindly provide the joblib's team with an example so that they can fix the problem.
输入参数:C:/Users/rit/Documents/PhD/Projects/\GLA/Input/LUWH/\LUWLAN_v1.0h\transit_model.nc range_to_large 1150
我如何摆脱警告?既然输入参数不太长,为什么会发生这种情况?
对于“为什么这不起作用?”我没有答案。问题的一部分。但是,要简单地忽略警告,您可以使用warnings.catch_warnings
with warnings.simplefilter
正如所见here https://docs.python.org/3/library/warnings.html#temporarily-suppressing-warnings.
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
your_code()
显然,我不建议忽略警告,除非你确定它无害,但如果你打算这样做,这种方式只会抑制上下文管理器内的警告,并且直接来自 python 文档
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)