Skip to content

Commit

Permalink
no longer casting to int in logical operations, closes #102 (7 years …
Browse files Browse the repository at this point in the history
…later... thanks Vlad :)
  • Loading branch information
stringertheory committed Feb 5, 2024
1 parent 9ac2097 commit 2e14e14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion tests/test_operations.py
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions traces/timeseries.py
Expand Up @@ -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."""
Expand Down

0 comments on commit 2e14e14

Please sign in to comment.