Skip to content

Commit

Permalink
from_numpy orientation (#3960) (#4233)
Browse files Browse the repository at this point in the history
Co-authored-by: Stijn de Gooijer <stijn@degooijer.io>
  • Loading branch information
ritchie46 and stinodego committed Aug 8, 2022
1 parent e0f52d1 commit 3d51dca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
30 changes: 6 additions & 24 deletions py-polars/polars/internals/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,40 +170,22 @@ def __rpow__(self, base: int | float | Expr) -> Expr:
return pli.expr_to_lit_or_expr(base) ** self

def __ge__(self, other: Any) -> Expr:
return self.gt_eq(self.__to_expr(other))
return wrap_expr(self._pyexpr.gt_eq(self.__to_expr(other)._pyexpr))

def __le__(self, other: Any) -> Expr:
return self.lt_eq(self.__to_expr(other))
return wrap_expr(self._pyexpr.lt_eq(self.__to_expr(other)._pyexpr))

def __eq__(self, other: Any) -> Expr: # type: ignore[override]
return self.eq(self.__to_expr(other))
return wrap_expr(self._pyexpr.eq(self.__to_expr(other)._pyexpr))

def __ne__(self, other: Any) -> Expr: # type: ignore[override]
return self.neq(self.__to_expr(other))
return wrap_expr(self._pyexpr.neq(self.__to_expr(other)._pyexpr))

def __lt__(self, other: Any) -> Expr:
return self.lt(self.__to_expr(other))
return wrap_expr(self._pyexpr.lt(self.__to_expr(other)._pyexpr))

def __gt__(self, other: Any) -> Expr:
return self.gt(self.__to_expr(other))

def eq(self, other: Expr) -> Expr:
return wrap_expr(self._pyexpr.eq(other._pyexpr))

def neq(self, other: Expr) -> Expr:
return wrap_expr(self._pyexpr.neq(other._pyexpr))

def gt(self, other: Expr) -> Expr:
return wrap_expr(self._pyexpr.gt(other._pyexpr))

def gt_eq(self, other: Expr) -> Expr:
return wrap_expr(self._pyexpr.gt_eq(other._pyexpr))

def lt_eq(self, other: Expr) -> Expr:
return wrap_expr(self._pyexpr.lt_eq(other._pyexpr))

def lt(self, other: Expr) -> Expr:
return wrap_expr(self._pyexpr.lt(other._pyexpr))
return wrap_expr(self._pyexpr.gt(self.__to_expr(other)._pyexpr))

def __neg__(self) -> Expr:
return pli.lit(0) - self
Expand Down
11 changes: 7 additions & 4 deletions py-polars/tests/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@

def test_lazy() -> None:
df = pl.DataFrame({"a": [1, 2, 3], "b": [1.0, 2.0, 3.0]})
_ = df.lazy().with_column(lit(1).alias("foo")).select([col("a"), col("foo")])
_ = df.lazy().with_column(pl.lit(1).alias("foo")).select([col("a"), col("foo")])

# test if it executes
_ = (
df.lazy()
.with_column(
when(col("a").gt(lit(2))).then(lit(10)).otherwise(lit(1)).alias("new")
when(pl.col("a") > pl.lit(2))
.then(pl.lit(10))
.otherwise(pl.lit(1))
.alias("new")
)
.collect()
)
Expand Down Expand Up @@ -922,10 +925,10 @@ def test_expr_bool_cmp() -> None:
df = pl.DataFrame({"a": [1, 2, 3, 4, 5], "b": [1, 2, 3, 4, 5]})

with pytest.raises(ValueError):
df.select([pl.col("a").gt(pl.col("b")) and pl.col("b").gt(pl.col("b"))])
df.select([(pl.col("a") > pl.col("b")) and (pl.col("b") > pl.col("b"))])

with pytest.raises(ValueError):
df.select([pl.col("a").gt(pl.col("b")) or pl.col("b").gt(pl.col("b"))])
df.select([(pl.col("a") > pl.col("b")) or (pl.col("b") > pl.col("b"))])


def test_is_in() -> None:
Expand Down

0 comments on commit 3d51dca

Please sign in to comment.