From 2e14e14effd70ad248981ee92032b98bac8b8ee3 Mon Sep 17 00:00:00 2001 From: stringertheory Date: Sun, 4 Feb 2024 23:46:26 -0600 Subject: [PATCH] no longer casting to int in logical operations, closes #102 (7 years later... thanks Vlad :) --- tests/test_operations.py | 11 ++++++++++- traces/timeseries.py | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/test_operations.py b/tests/test_operations.py index 3129f10..003333f 100644 --- a/tests/test_operations.py +++ b/tests/test_operations.py @@ -188,7 +188,16 @@ def test_logical_operations(): assert list(ts1.logical_and(ts2).items()) == a_and assert list((ts1 & ts2).items()) == a_and - a_xor = [(0, 0), (1, 1), (2, 0), (3, 1), (4, 1), (5, 0), (10, 0), (11, 1)] + a_xor = [ + (0, False), + (1, True), + (2, False), + (3, True), + (4, True), + (5, False), + (10, False), + (11, True), + ] assert list(ts1.logical_xor(ts2).items()) == a_xor assert list((ts1 ^ ts2).items()) == a_xor diff --git a/traces/timeseries.py b/traces/timeseries.py index a77a89d..f21c526 100644 --- a/traces/timeseries.py +++ b/traces/timeseries.py @@ -939,15 +939,15 @@ def multiply(self, other): def logical_and(self, other): """logical_and(t) = self(t) and other(t).""" - return self.operation(other, lambda x, y: int(x and y)) + return self.operation(other, lambda x, y: x and y) def logical_or(self, other): """logical_or(t) = self(t) or other(t).""" - return self.operation(other, lambda x, y: int(x or y)) + return self.operation(other, lambda x, y: x or y) def logical_xor(self, other): """logical_xor(t) = self(t) ^ other(t).""" - return self.operation(other, lambda x, y: int(bool(x) ^ bool(y))) + return self.operation(other, lambda x, y: bool(x) ^ bool(y)) def __setitem__(self, time, value): """Allow a[time] = value syntax or a a[start:end]=value."""