草庐IT

TRAVIS_COMMIT_RANGE

全部标签

python - 为 Travis 构建同时安装 Python 和 R?

我一直在研究一个R包,它通过简单的服务器脚本和套接字连接与Python交互。我可以在我自己的机器上测试,但我也想在Travis构建上测试它(我不想经历设置LinuxVM的努力)。为此,我需要一个Python安装,我可以将路径传递到我的R包测试中,以及一个要使用的端口号。我看过thisanswer这表明可以安装多个Python版本,但我不确定如何处理指定Python可执行文件的路径为测试选择一个端口号。还应注意,我用于Python“服务器”的Python脚本使用“localhost”。是否可以在Travis上做我想做的事?我应该和Travis一起做这件事吗?编辑这是我的Travis配置:

python - 值错误 : A value in x_new is below the interpolation range

这是我在执行时遇到的scikit-learn错误my_estimator=LassoLarsCV(fit_intercept=False,normalize=False,positive=True,max_n_alphas=1e5)请注意,如果我将max_n_alphas从1e5降低到1e4,我就不会再收到此错误。有人知道发生了什么事吗?调用时出现错误my_estimator.fit(x,y)我在40维度上有40k个数据点。完整的堆栈跟踪如下所示File"/usr/lib64/python2.7/site-packages/sklearn/linear_model/least_angl

python - IPython笔记本交互函数: how to set the slider range

我在Ipythonnotebook中编写了下面的代码来生成一个由参数a控制的sigmoid函数,a定义了sigmoid中心的位置,b定义了它的宽度:%matplotlibinlineimportnumpyasnpimportmatplotlib.pyplotaspltdefsigmoid(x,a,b):#sigmoidfunctionwithparametersa=center;b=widths=1/(1+np.exp(-(x-a)/b))return100.0*(s-min(s))/(max(s)-min(s))#normalizesigmoidto0-100x=np.linspac

python - Pandas date_range 从结束日期到开始日期

我正在尝试使用Python生成一系列半年度日期。Pandas提供了一个函数pd.date_range为了解决这个问题,我希望我的日期范围从结束日期开始并向后迭代。例如给定输入:start=datetime.datetime(2016,2,8)end=datetime.datetime(2018,6,1)pd.date_range(start,end,freq='6m')结果是:DatetimeIndex(['2016-02-29','2016-08-31','2017-02-28','2017-08-31','2018-02-28'])如何生成以下内容:DatetimeIndex(['

python - 如果测试没有足够的 python 覆盖率,如何让 travis 失败

如果我的测试没有足够的覆盖率,我可能会让travis失败,例如通常我使用以下travis配置条目运行我的测试。script:-coveragerun--source="mytestmodule"setup.pytest 最佳答案 根据这个link,如果您将--fail-under开关添加到coveragereport命令,它将以非零退出代码退出(travis将其视为失败)如果代码覆盖率低于给定的百分比。这将使您的.travis.yml文件的脚本部分看起来像:script-coveragerun--source="mytestmodu

python 3 : Most efficient way to create a [func(i) for i in range(N)] list comprehension

假设我有一个函数func(i),它为整数i创建一个对象,而N是某个非负整数。那么创建等于此列表的列表(不是范围)的最快方法是什么mylist=[func(i)foriinrange(N)]不求助于高级方法,例如在C中创建函数?我对上述列表理解的主要关注是我不确定python是否事先知道range(N)的长度来预分配mylist,因此必须逐步重新分配列表。是这种情况还是python足够聪明,可以先将mylist分配给长度N,然后再计算它的元素?如果没有,创建mylist的最佳方法是什么?也许是这个?mylist=[None]*Nforiinrange(N):mylist[i]=func(

Python 3 统一码解码错误 : 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

我正在实现这个notebook在使用Python3.5.3的Windows上,在load_vectors()调用中出现跟随错误。我尝试了不同的解决方案,但都没有奏效。inload_vectors(loc)1defload_vectors(loc):2return(load_array(loc+'.dat'),---->3pickle.load(open(loc+'_words.pkl','rb')),4pickle.load(open(loc+'_idx.pkl','rb')))UnicodeDecodeError:'ascii'codeccan'tdecodebyte0xe2inpo

python - 'ascii' 编解码器无法对位置 9 : ordinal not in range(128) 中的字符 u'\u2013' 进行编码

我正在尝试导入到cvs,但出现此错误UnicodeEncodeErrorat/brokers/csv/'ascii'codeccan'tencodecharacteru'\u2013'inposition9:ordinalnotinrange(128)Unicode错误提示无法编码/解码的字符串是:)758–9800我已经尝试过.encode、unicode()等,但没有任何效果,我不知道我是否需要一个库或其他东西,因为我在其他机器上有相同的代码并且工作正常。defexportar_a_csv_brokers(request):#Fechaactualhoy=datetime.now(

Python 索引错误 : tuple index out of range

非常感谢对此问题的反馈importsubprocessdefmain():'''Here'swherethewholethingstarts.'''#Editthisconstanttochangethefilenameinthegitlogcommand.FILE_NAME='file1.xml'#Dothegitdescribecommandtogetthetagnames.gitDescribe='gitdescribe--tags`gitrev-list--tags--max-count=2`'print('Invoking:{0}'.format(gitDescribe))p

python - `ValueError: A value in x_new is above the interpolation range.` - 除了不提升值还有什么其他原因?

我在scipyinterp1d函数中收到此错误。通常,如果x不是单调递增,就会产生此错误。importscipy.interpolateasspidefrefine(coarsex,coarsey,step):finex=np.arange(min(coarsex),max(coarsex)+step,step)intfunc=spi.interp1d(coarsex,coarsey,axis=0)finey=intfunc(finex)returnfinex,fineyfornum,tfileinenumerate(files):tfile=tfile.dropna(how='any