Skip to content

Commit

Permalink
Turn on doctests; fix wrong examples (#4060)
Browse files Browse the repository at this point in the history
  • Loading branch information
zundertj committed Jul 18, 2022
1 parent 7cfa390 commit 25e9cef
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 86 deletions.
4 changes: 2 additions & 2 deletions py-polars/polars/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def set_tbl_cols(cls, n: int) -> type[Config]:
Examples
--------
>>> pl.cfg.Config.set_tbl_cols(5)
>>> pl.cfg.Config.set_tbl_cols(5) # doctest: +IGNORE_RESULT
>>> df = pl.DataFrame({str(i): [i] for i in range(100)})
>>> df
shape: (1, 100)
Expand All @@ -83,7 +83,7 @@ def set_tbl_cols(cls, n: int) -> type[Config]:
│ 0 ┆ 1 ┆ 2 ┆ ... ┆ 98 ┆ 99 │
└─────┴─────┴─────┴─────┴─────┴─────┘
>>> pl.cfg.Config.set_tbl_cols(10)
>>> pl.cfg.Config.set_tbl_cols(10) # doctest: +IGNORE_RESULT
>>> df
shape: (1, 100)
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
Expand Down
110 changes: 55 additions & 55 deletions py-polars/polars/internals/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,17 +519,17 @@ def keep_name(self) -> Expr:
... )
>>> df.groupby("a").agg(pl.col("b").list()).sort(by="a")
shape: (3, 2)
┌─────┬───────────
│ a ┆ b_agg_list
│ --- ┆ ---
│ i64 ┆ list[str]
╞═════╪═══════════
│ 1 ┆ ["a"]
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌
│ 2 ┆ ["b"]
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌
│ 3 ┆ [null]
└─────┴───────────
┌─────┬───────────┐
│ a ┆ b
│ --- ┆ --- │
│ i64 ┆ list[str] │
╞═════╪═══════════╡
│ 1 ┆ ["a"] │
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
│ 2 ┆ ["b"] │
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
│ 3 ┆ [null] │
└─────┴───────────┘
Keep the original column name:
Expand Down Expand Up @@ -1107,7 +1107,7 @@ def drop_nulls(self) -> Expr:
╞═════╡
│ 4.0 │
├╌╌╌╌╌┤
5.0 │
4.0 │
├╌╌╌╌╌┤
│ NaN │
└─────┘
Expand Down Expand Up @@ -1139,7 +1139,7 @@ def drop_nans(self) -> Expr:
├╌╌╌╌╌╌┤
│ 4.0 │
├╌╌╌╌╌╌┤
5.0 │
4.0 │
└──────┘
"""
return wrap_expr(self._pyexpr.drop_nans())
Expand Down Expand Up @@ -1173,13 +1173,13 @@ def cumsum(self, reverse: bool = False) -> Expr:
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═══════════╡
838
110
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
17 ┆ 30
3 ┆ 9
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
27 ┆ 21
6 ┆ 7
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
3811
104
└─────┴───────────┘
"""
return wrap_expr(self._pyexpr.cumsum(reverse))
Expand Down Expand Up @@ -1208,19 +1208,19 @@ def cumprod(self, reverse: bool = False) -> Expr:
... ]
... )
shape: (4, 2)
┌─────┬───────────┐
│ a ┆ a_reverse │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═══════════╡
8 ┆ 7920
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
72990
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
720 ┆ 110
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
7920 ┆ 11
└─────┴───────────┘
┌─────┬───────────┐
│ a ┆ a_reverse │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═══════════╡
1 ┆ 24
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
224
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
6 ┆ 12
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
24 ┆ 4
└─────┴───────────┘
"""
return wrap_expr(self._pyexpr.cumprod(reverse))

Expand Down Expand Up @@ -1248,13 +1248,13 @@ def cummin(self, reverse: bool = False) -> Expr:
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═══════════╡
88
11
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
89
12
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
810
13
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
811
14
└─────┴───────────┘
"""
return wrap_expr(self._pyexpr.cummin(reverse))
Expand Down Expand Up @@ -1283,13 +1283,13 @@ def cummax(self, reverse: bool = False) -> Expr:
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═══════════╡
811
14
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
811
24
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
811
34
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌┤
811
44
└─────┴───────────┘
"""
Expand All @@ -1314,7 +1314,7 @@ def cumcount(self, reverse: bool = False) -> Expr:
... pl.col("a").cumcount(reverse=True).alias("a_reverse"),
... ]
... )
>>> shape: (4, 2)
shape: (4, 2)
┌─────┬───────────┐
│ a ┆ a_reverse │
│ --- ┆ --- │
Expand Down Expand Up @@ -1459,7 +1459,7 @@ def mode(self) -> Expr:
... "b": [1, 1, 2, 2],
... }
... )
>>> df.select(pl.all().mode())
>>> df.select(pl.all().mode()) # doctest: +IGNORE_RESULT
shape: (2, 2)
┌─────┬─────┐
│ a ┆ b │
Expand Down Expand Up @@ -1565,28 +1565,28 @@ def sort(self, reverse: bool = False, nulls_last: bool = False) -> Expr:
│ --- │
│ i64 │
╞═══════╡
│ 99 │
├╌╌╌╌╌╌╌┤
│ 98 │
│ 1 │
├╌╌╌╌╌╌╌┤
4
2
├╌╌╌╌╌╌╌┤
│ 3 │
├╌╌╌╌╌╌╌┤
2
4
├╌╌╌╌╌╌╌┤
│ 1 │
│ 98 │
├╌╌╌╌╌╌╌┤
│ 99 │
└───────┘
>>> df.groupby("group").agg(pl.col("value").sort())
>>> df.groupby("group").agg(pl.col("value").sort()) # doctest: +IGNORE_RESULT
shape: (2, 2)
┌───────┬────────────┐
│ group ┆ value │
│ --- ┆ --- │
│ str ┆ list[i64] │
╞═══════╪════════════╡
│ one ┆ [1, 2, 98] │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ two ┆ [3, 4, 99] │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤
│ one ┆ [1, 2, 98] │
└───────┴────────────┘
"""
return wrap_expr(self._pyexpr.sort_with(reverse, nulls_last))
Expand Down Expand Up @@ -2095,9 +2095,9 @@ def max(self) -> Expr:
┌─────┐
│ a │
│ --- │
f64
i64
╞═════╡
│ 1.0
│ 1
└─────┘
"""
return wrap_expr(self._pyexpr.max())
Expand Down Expand Up @@ -2139,7 +2139,7 @@ def sum(self) -> Expr:
┌─────┐
│ a │
│ --- │
f64
i64
╞═════╡
│ 0 │
└─────┘
Expand Down Expand Up @@ -2217,7 +2217,7 @@ def n_unique(self) -> "Expr":
┌─────┐
│ a │
│ --- │
i64
u32
╞═════╡
│ 2 │
└─────┘
Expand Down Expand Up @@ -2291,7 +2291,7 @@ def unique(self, maintain_order: bool = False) -> Expr:
Examples
--------
>>> df = pl.DataFrame({"a": [1, 1, 2]})
>>> df.select(pl.col("a").unique())
>>> df.select(pl.col("a").unique()) # doctest: +IGNORE_RESULT
shape: (2, 1)
┌─────┐
│ a │
Expand Down Expand Up @@ -2583,7 +2583,7 @@ def quantile(self, quantile: float, interpolation: str = "nearest") -> Expr:
│ --- │
│ f64 │
╞═════╡
│ 1.2
│ 1.5
└─────┘
"""
Expand Down

0 comments on commit 25e9cef

Please sign in to comment.