在调查如何在 github 操作中,我可以将存储库中特定文件的“基本”版本与文件的拉取请求(“头”)版本进行比较......在调查这一点时,我发现了各种来源(例如,github.community和github.com/actions/checkout README 文件中的代码示例)...我发现以下上下文变量可用:
github.refgithub.shagithub.event.pull_request.head.refgithub.event.pull_request.head.shagithub.event.pull_request.base.refgithub.event.pull_request.base.sha但是,除了前两个(github.ref和github.sha)之外,我在任何 github actions 文档中都找不到其他四个。
我的问题是: 是否有任何地方记录了可用上下文变量的完整列表?
例如,我找到了 this,但它只列出了 github 上下文对象下一级的上下文变量。我找不到上述更深层嵌套变量的文档。可能还有其他可能非常有用的上下文变量,但我似乎找不到完整的列表,而只是那些碰巧被提及并分散在各种代码示例中的变量。
我计划从比特币数据中获取烛台图。这是我的代码,用于在加载 csv 文件后选择我想要的数据框。
df['Date'] = pd.to_datetime(df['Date'])
start_date = '2016-02-27'
end_date = '2021-02-27'
mask = (df['Date'] >= start_date) & (df['Date'] <= end_date)
df = df.loc[mask]
df
Run Code Online (Sandbox Code Playgroud)
然后,我输入了制作烛台图的代码,如下所示:
import matplotlib.pyplot as plt
! pip install --upgrade mplfinance
import mplfinance as mpf
import matplotlib.dates as mpl_dates
mpf.plot(df, type = 'candle', style = 'charles',
title = 'Bitcoin Price',
ylabel = 'Price (USD$)',
volume = True,
ylabel_lower = 'Shares \nTraded',
mav = (3,6,9),
savefig = 'chart-mplfinance.png')
Run Code Online (Sandbox Code Playgroud)
它说“TypeError:期望 data.index 作为 DatetimeIndex”。所以我在谷歌上查找了这个问题的解决方案,并尝试了这个:
df = dict()
df['Date'] = …Run Code Online (Sandbox Code Playgroud) 我在各种 GitHub Action 工作流程示例中注意到,通常在调用预定义操作(使用语法uses:)时,会指定该操作的特定版本。例如:
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
Run Code Online (Sandbox Code Playgroud)
上述工作流程指定了@v2和actions/checkout。actions/setup-python
问题是,如何知道哪个版本@v2是最好使用的版本?
我如何知道何时@v3可用?
更令人困惑的是用于发布到pypi 的pypa/gh-action-pypi-publish操作的情况。在我看过的示例中,我至少看到指定了四个不同的版本:
pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29pypa/gh-action-pypi-publish@masterpypa/gh-action-pypi-publish@v1pypa/gh-action-pypi-publish@release/v1我怎么知道该使用哪一个? 一般来说,您如何知道哪些可用,以及它们之间的差异是什么?
我正在使用 PIL 旋转一些图像,我注意到输出文件要小得多,所以我尝试了一个测试:除了保存 exif 信息之外,对文件不执行任何操作(因为我知道 PIL Image 默认情况下不会保存exif 信息)。所以这是我的测试代码:
from PIL import Image
test = Image.open('my_image_file.jpg')
holdexif = test.info["exif"]
test.save('my_saved_image_file.jpg',"jpeg",exif=holdexif)
Run Code Online (Sandbox Code Playgroud)
当我执行上述操作时,my_saved_image_file.jpg( ) 明显小于441 KB原始my_image_file( 1.83 MB)。 这是为什么? 缺什么?
当我查看两个文件的各种属性时,它们似乎是相同的。两者尺寸均为 56 英寸 x 27 英寸,均为每英寸 72 像素,均为 4032 x 1960 像素。 我绝不是图像文件方面的专家。 根据我检查过的这些内容(图像的大小、分辨率和外观),这些文件在我看来是相同的。据我所知,只有磁盘上的文件大小不同。我还应该看什么?还有什么可能不同?
我还尝试了quality=保存中的 kwarg:
test.save('my_saved_image_file.jpg',"jpeg",exif=holdexif,quality=95)
Run Code Online (Sandbox Code Playgroud)
1.73 MB这给了我一个几乎与原始文件 ( ) 一样大的文件( 1.83 MB)。但我不知道更大的尺寸有什么不同(而且我不明白是什么让“质量”更好;图像对我来说看起来是一样的)。我试图了解这两个文件之间到底有什么不同,以便我可以做出决定。也许较小的尺寸完全适合我的目的。
我想将我的面板分开,因为标题重叠了。ADX 标题位于 RSI 面板中。我尝试过tight_layout=True但还是一样。
我的代码:
ap0 = [
mpf.make_addplot(df['sma_200'],color='#FF0000', panel=2),
mpf.make_addplot(df['sma_50'],color='#ffa500', panel=2),
mpf.make_addplot(df['sma_20'],color='#00FF00', panel=2),
mpf.make_addplot(df['rsi'],color='#ffa500', panel=0, title="RSI"),
mpf.make_addplot(df['hline_30'], panel=0),
mpf.make_addplot(df['hline_70'], panel=0),
mpf.make_addplot(df['adx'],color='#0000FF', panel=1, secondary_y=False, title="ADX"),
mpf.make_addplot(df['-di'],color='#FF0000', panel=1, secondary_y=False),
mpf.make_addplot(df['+di'],color='#32cd32', panel=1, secondary_y=False),
mpf.make_addplot(df['hline_25'], panel=1, secondary_y=False)
]
fig, axlist = mpf.plot(
df,
panel_ratios=(.05, .05, .2, .05),
type="hollow_candle",
yscale='log',
volume=True,
title="{} - {}".format(ticker, interval),
style=mpf_style,
figsize=(12.8, 10),
returnfig=True,
closefig=True,
addplot=ap0,
main_panel=2,
volume_panel=3,
num_panels=4,
)
Run Code Online (Sandbox Code Playgroud)
这不是未命名名称空间优于静态名称的优势吗?
将其标记为重复之前,请仔细阅读该问题。我不是在问为什么使用未命名的名称空间而不是静态名称空间!
我问,为什么将Google测试放在未命名的命名空间中?这是Google测试遵循的一些约定吗?如果是,为什么?无论它们是否在未命名的名称空间中,测试都可以正常工作,因此显然不是必需的。**
我从github克隆了google测试,并为我的mac构建了它。它工作正常,但是我在示例测试代码中注意到,他们给了他们将测试放在未命名的名称空间中的条件。有人知道为什么吗?
例如,请参见以下文件:googletest / googletest / samples / sample1_unittest.cc(https://github.com/google/googletest/blob/master/googletest/samples/sample1_unittest.cc#L41)
该文件的一部分如下所示:
// Step 1. Include necessary header files such that the stuff your
// test logic needs is declared.
//
// Don't forget gtest.h, which declares the testing framework.
#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"
namespace {
// Step 2. Use the TEST macro to define your tests.
...
TEST(FactorialTest, Negative) {
// This test is named "Negative", …Run Code Online (Sandbox Code Playgroud) 如何将mpl_finance软件包安装到 Anaconda 上的环境路径中?
我试过了,pip install mpl_finance但是我在Anaconda上还是找不到这个包,它去哪里了?我对 Python 非常熟悉。
这是我的 tox.ini 文件:
dino@DINO:~/code/mplfinance$ cat tox.ini
[tox]
envlist = py36, py37, py38
[pytest]
python_files = tests.py
[testenv]
deps =
matplotlib
numpy
pandas
pytest
setenv =
# don't use interactive backend for matplotlib in e2e tests
MPLBACKEND = agg
commands =
pytest
Run Code Online (Sandbox Code Playgroud)
当我运行tox<Enter>它时,它会为指定的三个环境中的每一个启动 pytest。当 pytest 首次启动时(对于每个环境),它会报告 Python 的版本以及它正在使用的其他一些东西。例如,py36我看到:
py36 runtests: PYTHONHASHSEED='893013612'
py36 runtests: commands[0] | pytest
============= test session starts ==============
platform linux -- Python 3.6.7, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
rootdir: /home/dino/code/mplfinance, inifile: tox.ini
collected 2 items
tests.py …Run Code Online (Sandbox Code Playgroud) 通用代码如下:
import math
import matplotlib.pyplot as plt
x = [x for x in range(10)]
y = [math.sin(x) for x in x]
Run Code Online (Sandbox Code Playgroud)
以下两个代码片段产生完全相同的图:
ax = plt.subplot()
ax.scatter(x,y,label='AAA')
ax.legend()
print('ax.get_legend_handles_labels() returns:\n',ax.get_legend_handles_labels())
plt.show()
Run Code Online (Sandbox Code Playgroud)
ax = plt.subplot()
ax.scatter(x,y)
ax.legend(labels=['AAA'])
print('ax.get_legend_handles_labels() returns:\n',ax.get_legend_handles_labels())
plt.show()
Run Code Online (Sandbox Code Playgroud)
第一个片段中的 print 语句返回
ax.get_legend_handles_labels() returns:
([<matplotlib.collections.PathCollection object at 0x7fc32cbdfac0>], ['AAA'])
Run Code Online (Sandbox Code Playgroud)
但第二个片段给出:
ax.get_legend_handles_labels() returns:
([], [])
Run Code Online (Sandbox Code Playgroud)
为什么get_legend_handles_labels()在第二种情况下返回空列表,但结果图是相同的?
我在这里查看一些示例代码(https://docs.python.org/2.0/api/refcountDetails.html)并试图更好地理解两个示例之间的差异:第一个示例是:
PyObject *t;
t = PyTuple_New(3);
PyTuple_SetItem(t, 0, PyInt_FromLong(1L));
PyTuple_SetItem(t, 1, PyInt_FromLong(2L));
PyTuple_SetItem(t, 2, PyString_FromString("three"));
Run Code Online (Sandbox Code Playgroud)
作者解释说 PyTuple_SetItem()窃取了引用(因此无需 DECREF)。 好吧,我明白了。然后作者使用 PySequence_SetItem() 提供了类似的代码,它不会窃取引用,因此调用者必须 DECREF,示例代码如下所示:
PyObject *l, *x;
l = PyList_New(3);
x = PyInt_FromLong(1L);
PySequence_SetItem(l, 0, x); Py_DECREF(x);
x = PyInt_FromLong(2L);
PySequence_SetItem(l, 1, x); Py_DECREF(x);
x = PyString_FromString("three");
PySequence_SetItem(l, 2, x); Py_DECREF(x);
PyObject *l, *x;
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果第二个示例与第一个示例类似,传递 PyTYPE_FromSOMETYPE 如下,会发生什么?
PyObject *l;
l = PyList_New(3);
PySequence_SetItem(l, 0, PyInt_FromLong(1L));
PySequence_SetItem(l, 1, PyInt_FromLong(2L));
PySequence_SetItem(l, 2, PyString_FromString("three"));
Run Code Online (Sandbox Code Playgroud)
最后一种情况是良性的,还是会导致内存泄漏(因为 PySequence_SetItem 不会取得 PyInt_FromLong …
python ×5
mplfinance ×3
matplotlib ×2
anaconda ×1
c++ ×1
conda ×1
googletest ×1
pycharm ×1
pytest ×1
python-3.x ×1
python-c-api ×1
tox ×1
unit-testing ×1