Using `x > pipe | foo | bar` gives different results than `(pipe | foo | bar)(x)`
pickledish opened this issue · 3 comments
Not totally sure about anything here (this is my first time leaving a bug) but it seems like I've found a situation where these two seemingly-the-same statements do different things. I've included a minimal example:
import numpy as np
from pipetools import pipe
def scaleDiagonal(matrix):
m = np.copy(matrix)
size = matrix.shape[0]
smallest = min([ m[i,i] for i in range(size) ])
for i in range(size):
m[i,i] = m[i,i] / smallest
return m
x = np.array([1,2,3,4,5,6,7,8,9]).reshape(3,3)
y = (pipe | scaleDiagonal)(x) # Works
z = x > pipe | scaleDiagonal # Errors
Hey, thanks for the report!
The limitation of the x > pipe
syntax is that it's not going to work if x
has __gt__
defined - which is probably the case for np.array
. This should probably be mentioned in the documentation.
I looked into it a bit and there is really nothing straight forward that can be done about this. Since __gt__
on the input object will be called before __lt__
on the pipe, if the object returns a result there is no way to intercept it.
So at least I added a note about this in the docs.
Yeah, no that makes sense -- I'm not surprised! Just nice that there's a note of it now so people aren't caught off guard. Thanks!