Open cpcloud opened 9 years ago
Recap from the mailing list:
It'd be nice to be able to select values in columns based on values in other columns. SQL does this with case expressions:
case
select case when a == 1 then b + 1 when c == 2 then a else a end from table
SQLAlchemy implements this as well: http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.expression.case
NumPy has a special case of this (pun intended), namely np.where.
np.where
I propose that we do something similar in blaze. We need to preserve the order of the cases, in the case of overlapping conditions.
Proposed syntax:
d = Data(..., dshape='var {a: int64, b: float64, c: int8}') cased = case( (d.a == 1, d.b + 1), (d.c == 2, d.a), otherwise=d.a )
In the otherwise case, should the = be a comma and is otherwise an alias of True?
otherwise
=
True
No, I was thinking it should be the only allowed keyword argument
Ah, that is pretty nice.
Recap from the mailing list:
It'd be nice to be able to select values in columns based on values in other columns. SQL does this with
case
expressions:SQLAlchemy implements this as well: http://docs.sqlalchemy.org/en/latest/core/sqlelement.html#sqlalchemy.sql.expression.case
NumPy has a special case of this (pun intended), namely
np.where
.I propose that we do something similar in blaze. We need to preserve the order of the cases, in the case of overlapping conditions.
Proposed syntax: