小编led*_*uss的帖子

如果“pandas.testing.assert_frame_equal”失败,如何输出所有差异?

我正在对数据框输出进行单元测试。我有两个数据框,在多列上具有不同的值

df1 = pd.DataFrame({"col1": [1, 1], "col2":[1, 1]})
df2 = pd.DataFrame({"col1": [1, 2], "col2":[1, 2]})
Run Code Online (Sandbox Code Playgroud)

当我运行时pandas.testing.assert_frame_equal,出现以下错误,只有一列:

DataFrame.iloc[:, 0] (column name="col1") values are different (50.0 %)
[index]: [0, 1]
[left]:  [1, 1]
[right]: [1, 2]
Run Code Online (Sandbox Code Playgroud)

但是,我没有关于第二列的信息。有没有办法显示所有不匹配,而不仅仅是最左侧列中的第一个不匹配?

python unit-testing pandas

4
推荐指数
1
解决办法
2355
查看次数

Python:跨线程共享类变量

我在一个类的许多实例之间共享一个计数器(training_queue).该类继承了threading.Thread,因此它实现了run()方法.当我调用start()时,我希望每个线程都增加这个计数器,所以当它达到一个限制时,不再启动线程.但是,没有一个线程修改变量.这是代码:

class Engine(threading.Thread):

training_mutex = threading.Semaphore(MAX_TRAIN)
training_queue = 0
analysis_mutex = threading.Semaphore(MAX_ANALYSIS)
analysis_queue = 0
variable_mutex = threading.Lock()


def __init__(self, config):
    threading.Thread.__init__(self)
    self.config = config
    self.deepnet = None
    # prevents engine from doing analysis while training
    self.analyze_lock = threading.Lock()

def run(self):
    with self.variable_mutex:
        self.training_queue += 1
    print self.training_queue
    with self.training_mutex:
        with self.analyze_lock:
            self.deepnet = self.loadLSTM3Model()
Run Code Online (Sandbox Code Playgroud)

我使用Lock保护training_queue,因此它应该是线程安全的.但是,如果我总是打印它的值1.在这种情况下,线程如何影响变量范围?

python python-multithreading

3
推荐指数
1
解决办法
4886
查看次数