Skip to content

Commit

Permalink
Fix doctest and test dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
mcrumiller committed Sep 18, 2024
1 parent 3cc6a38 commit 5d8fa56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
24 changes: 10 additions & 14 deletions py-polars/polars/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10052,33 +10052,29 @@ def hist(
--------
>>> df = pl.DataFrame({"a": [1, 3, 8, 8, 2, 1, 3]})
>>> df.select(pl.col("a").hist(bins=[1, 2, 3]))
shape: (4, 1)
shape: (2, 1)
┌─────┐
│ a │
│ --- │
│ u32 │
╞═════╡
│ 2 │
│ 1 │
│ 2 │
│ 2 │
└─────┘
>>> df.select(
... pl.col("a").hist(
... bins=[1, 2, 3], include_breakpoint=True, include_category=True
... )
... )
shape: (4, 1)
┌───────────────────────┐
│ a │
│ --- │
│ struct[3] │
╞═══════════════════════╡
│ {1.0,"(-inf, 1.0]",2} │
│ {2.0,"(1.0, 2.0]",1} │
│ {3.0,"(2.0, 3.0]",2} │
│ {inf,"(3.0, inf]",2} │
└───────────────────────┘
shape: (2, 1)
┌──────────────────────┐
│ a │
│ --- │
│ struct[3] │
╞══════════════════════╡
│ {2.0,"(1.0, 2.0]",1} │
│ {3.0,"(2.0, 3.0]",2} │
└──────────────────────┘
"""
if bins is not None:
if isinstance(bins, list):
Expand Down
4 changes: 2 additions & 2 deletions py-polars/tests/unit/operations/test_hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def test_hist_all_null() -> None:
@pytest.mark.parametrize("n_values", [3, 10, 250])
def test_hist_rand(n_values: int, n_null: int) -> None:
s_rand = pl.Series([None] * n_null, dtype=pl.Int64)
s_values = pl.Series(np.random.randint(0, 100, n_values))
s_values = pl.Series(np.random.randint(0, 100, n_values), dtype=pl.Int64)
s = pl.concat((s_rand, s_values))
out = s.hist(bin_count=10)

Expand All @@ -395,7 +395,7 @@ def test_hist_floating_point() -> None:

np.random.seed(2)
s_rand = pl.Series([None] * n_null, dtype=pl.Int64)
s_values = pl.Series(np.random.randint(0, 100, n_values))
s_values = pl.Series(np.random.randint(0, 100, n_values), dtype=pl.Int64)
s = pl.concat((s_rand, s_values))
out = s.hist(bin_count=10)
min_edge = s.min() - (s.max() - s.min()) * 0.001 # type: ignore[operator]
Expand Down

0 comments on commit 5d8fa56

Please sign in to comment.