我有一个常见的py.test fixture,我想在同一个模块中的不同测试文件中使用.在阅读py.test文档之后,建议将夹具添加到conftest.py文件中,该文件应该使夹具可用于模块中的所有文件.但由于某些原因,我似乎无法使用这个常用夹具来使用我的测试类.
#In conftest.py
import pytest
@pytest.fixture
def mock_data(scope="module"):
return ({'number_of_females_1': 14,
'number_of_females_2': 3,
'number_of_females_3': 19,
'number_of_males_1': 37)}
Run Code Online (Sandbox Code Playgroud)
然后在我的测试类文件中
Import pytest
from unittest import TestCase
@pytest.mark.usefixtures('mgmt_data')
class Test_param_sweeps(TestCase):
def test_Base_model(self, mgmt_data):
from pyugend.pyugend.Models import Base_model
t = Base_model(**mgmt_data)
assert isinstance(t, Base_model)
Run Code Online (Sandbox Code Playgroud)
文档说我没有必要导入mgmt_data夹具或任何东西.
运行此测试用例时出现的错误是:
self = <pyugend.tests.test_param_sweeps.Test_param_sweeps testMethod=test_Base_model>
result = <TestCaseFunction 'test_Base_model'>
def run(self, result=None):
orig_result = result
if result is None:
result = self.defaultTestResult()
startTestRun = getattr(result, 'startTestRun', None)
if startTestRun is not None:
startTestRun()
result.startTest(self) …Run Code Online (Sandbox Code Playgroud) 我是谷歌地球引擎的新手,并试图了解如何使用谷歌地球引擎 python api。我可以创建一个图像集合,但显然该getdownloadurl()方法仅适用于单个图像。所以我试图了解如何迭代和下载集合中的所有图像。
这是我的基本代码。对于我正在做的其他一些工作,我非常详细地分解了它。
import ee
ee.Initialize()
col = ee.ImageCollection('LANDSAT/LC08/C01/T1')
col.filterDate('1/1/2015', '4/30/2015')
pt = ee.Geometry.Point([-2.40986111110000012, 26.76033333330000019])
buff = pt.buffer(300)
region = ee.Feature.bounds(buff)
col.filterBounds(region)
Run Code Online (Sandbox Code Playgroud)
所以我拉了 Landsat 集合,按日期和缓冲区几何过滤。所以我应该在集合中有 7-8 张图片(所有乐队)。
但是,我似乎无法通过迭代来处理集合。
例如:
for i in col:
print(i)
Run Code Online (Sandbox Code Playgroud)
错误表明 TypeError: 'ImageCollection' object is not iterable
因此,如果集合不可迭代,我如何访问单个图像?
一旦我有了图像,我应该可以使用通常的
path = col[i].getDownloadUrl({
'scale': 30,
'crs': 'EPSG:4326',
'region': region
})
Run Code Online (Sandbox Code Playgroud) 我能否以与目前查看降价文件相同的方式在github上显示asciidoc文件?根据此博客条目,我应该能够做到这一点:
如果您对使用AsciiDoc感兴趣,请转到GitHub并使用文件扩展名.asciidoc或.adoc在您的某个存储库或要点中创建一个新文件.
但是我试图这样做但它没有用.任何人都可以告诉我如何获得asciidoc文档在Github上显示格式正确的文本?
这是我试图用Asciidoc测试的文档. https://github.com/00krishna/proj_blog/blob/master/test.adoc
我有一个 numpy 一维结构化数组,我只想获取一条记录的一部分。我试图弄清楚如何分割这种类型的请求。这是我的代码:
summary_stat_list = ['mean', 'variance', 'median', 'kurtosis', 'skewness']
model_summary_stats = np.zeros(5,dtype=[('statistic',
'object'),
('f1', 'float'),
('f2', 'float'),
('f3', 'float'),
('m1', 'float'),
('m2', 'float'),
('m3', 'float'),
('t3', 'float'),
('t2', 'float'),
('t1', 'float'),
('prom1', 'float'),
('prom2', 'float')])
for r in range(model_summary_stats.shape[0]):
model_summary_stats['statistic'][r] = summary_stat_list[r]
Run Code Online (Sandbox Code Playgroud)
现在,该数组如下所示:
[('mean', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
('variance', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
('median', 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) …Run Code Online (Sandbox Code Playgroud) 我正在构建一个中等大小的 C++ 库,并CMakeLists.txt从一堆不同的示例等中拼凑了我的文件。我试图了解include_directories与target_link_libraries指令之间的区别。
我在下面列出了我的一些代码,但只是想以评论作为序言。我使用该Boost库来构建我的一些代码。所以我有一个指令来INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})在构建过程中包含 Boost 源目录。所以我假设 Cmake 在构建任何可执行文件时将包含这些 Boost 源文件——没有任何额外的显式指令。
但后来我TARGET_LINK_LIBRARIES( gd_validator ${Boost_LIBRARIES} )在构建可执行文件时有一个。所以这表明我不仅需要包含 Boost 目录,而且还需要将它与可执行文件显式链接。
所以我不确定我是否真的需要这两个步骤,或者我是否只需要INCLUDE_DIRECTORIES指令,仅此而已。
cmake_minimum_required(VERSION 3.7)
project(XXX)
find_package(Boost 1.58.0 REQUIRED COMPONENTS system filesystem program_options chrono timer date_time REQUIRED)
if(NOT Boost_FOUND)
message(FATAL_ERROR "NOTICE: This demo requires Boost and will not be compiled.")
endif()
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
file(GLOB lib_SRC RELATIVE "lib/" "*.h" "*.cpp")
file(GLOB test_SRC RELATIVE "tests/" "*.h" "*.cpp")
# …Run Code Online (Sandbox Code Playgroud) 我正在创建一个小部件,它仅执行笔记本中的某些单元格,以根据更改的数据生成新的绘图。虽然 Jupyter 可以执行诸如执行笔记本中的所有单元格或执行当前单元格下方的所有单元格等操作。
相反,我想为我想要有选择地执行的单元格创建标签。然后,当我按下按钮时,我可以执行此代码并运行单元格。
小部件代码本身并不重要——这部分很简单。更难的是弄清楚如何在笔记本中实现python和javascript之间的通信。有人有主意吗。
我正在尝试将 Pandas Dataframe MultiIndex 展平,以便只有一个级别的索引。基于任意数量的 SE 帖子的通常解决方案是使用该df.reset_index命令,但这并不能解决问题。
我从 an 开始Xarray DataArray并将其转换为数据帧。原始数据框看起来像这样。
results
simdata a_ss_yr attr attr1 attr2 attr3
run year
0 0 0 0 0 0 0
1 1 6 2 0 4
2 2 4 2 2 0
3 3 1 0 0 1
4 4 2 0 2 0
Run Code Online (Sandbox Code Playgroud)
展平我使用的索引
df.reset_index(drop=True)
Run Code Online (Sandbox Code Playgroud)
这只完成了这个:
run year results
simdata a_ss_yr attr attr1 attr2
0 0 0 0 0 0 0
1 0 1 1 6 2 0 …Run Code Online (Sandbox Code Playgroud) 我在将Python 3.6类中的变量分配给特定类型(Pathlib路径)时遇到麻烦。按照link的示例,我尝试创建一个TypeVar,但mypy仍然抛出错误。我想确保__init__.py仅在初始化时初始化的类变量在编译时就接收到特定类型。因此,这只是一项检查,以确保我不会无意中为这些类变量设置字符串或其他内容。
有人可以建议正确的方法吗?
这是一些简单的代码。
import pathlib
from typing import Union, Dict, TypeVar, Type
Pathtype = TypeVar('Pathtype', bound=pathlib.Path)
class Request:
def __init__(self, argsdict):
self._dir_file1: Type[Pathtype] = argsdict['dir_file1']
self._dir_file2: Type[Pathtype] = argsdict['dir_file2']
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
Request.py:13: error: Invalid type "Request.Pathtype"
Request.py:14: error: Invalid type "Request.Pathtype"
Run Code Online (Sandbox Code Playgroud) 我正在Hackernoon 上阅读这篇关于函数如何不是反射等变的博客文章Tensorflow's tf.image.resize_area()。因此,如果我要在某些数据增强步骤中调整图像大小,这可能会真正搞砸模型训练。
作者继续说,用户不应该使用任何tf.image.resize功能,因为潜在的不可预测的行为。这篇文章来自 2018 年 1 月,所以不久前。其实我看了文章的评论区,没有人提到问题已经解决。
我只是想知道这些问题是否仍然存在,解决方法是什么?后续版本中的任何更改tensorflow。比如我可以使用tf.keras增强函数来避免这些问题吗?
我试图推出新的filesystemSTL库,但由于某种原因我遇到了错误.该Clang++7网站表明它应该支持新的filesystem图书馆 - 事实上我clang已经超前了g++.
我使用了另一个Stack Exchange帖子中的一些代码,因此根据upvotes的数量它应该是有效的.这可能会转到指定的目录并打印该目录中的所有文件.这是代码.
#include <iostream>
#include <string>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
int main(int argc, char *argv[])
{
std::string path = "/home/.../Downloads";
for (const auto & entry : fs::directory_iterator(path))
{
std::cout << entry.path() << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误消息是:
CMakeFiles/filesystem_app.dir/main.cpp.o: In function `main':
/media/.../clangcpp/filesystem_app/main.cpp:13: undefined reference to `std::experimental::filesystem::v1::__cxx11::directory_iterator::operator*() const'
/media/.../clangcpp/filesystem_app/main.cpp:13: undefined reference to `std::experimental::filesystem::v1::__cxx11::directory_iterator::operator++()'
CMakeFiles/filesystem_app.dir/main.cpp.o: In function `path<std::__cxx11::basic_string<char>, std::experimental::filesystem::v1::__cxx11::path>':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0/../../../../include/c++/5.5.0/experimental/fs_path.h:198: undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'
CMakeFiles/filesystem_app.dir/main.cpp.o: In function `directory_iterator': …Run Code Online (Sandbox Code Playgroud)