Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Jan 8, 2024
1 parent 5380b2f commit 503699c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
50 changes: 30 additions & 20 deletions py-polars/polars/functions/range/int_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

@overload
def arange(
start: int | IntoExprColumn,
end: int | IntoExprColumn,
start: int | IntoExprColumn = ...,
end: int | IntoExprColumn | None = ...,
step: int = ...,
*,
dtype: PolarsIntegerType = ...,
Expand All @@ -32,8 +32,8 @@ def arange(

@overload
def arange(
start: int | IntoExprColumn,
end: int | IntoExprColumn,
start: int | IntoExprColumn = ...,
end: int | IntoExprColumn | None = ...,
step: int = ...,
*,
dtype: PolarsIntegerType = ...,
Expand All @@ -44,8 +44,8 @@ def arange(

@overload
def arange(
start: int | IntoExprColumn,
end: int | IntoExprColumn,
start: int | IntoExprColumn = ...,
end: int | IntoExprColumn | None = ...,
step: int = ...,
*,
dtype: PolarsIntegerType = ...,
Expand All @@ -55,8 +55,8 @@ def arange(


def arange(
start: int | IntoExprColumn,
end: int | IntoExprColumn,
start: int | IntoExprColumn = 1,
end: int | IntoExprColumn | None = None,
step: int = 1,
*,
dtype: PolarsIntegerType = Int64,
Expand Down Expand Up @@ -107,8 +107,8 @@ def arange(

@overload
def int_range(
start: int | IntoExprColumn,
end: int | IntoExprColumn,
start: int | IntoExprColumn = ...,
end: int | IntoExprColumn | None = ...,
step: int = ...,
*,
dtype: PolarsIntegerType = ...,
Expand All @@ -119,8 +119,8 @@ def int_range(

@overload
def int_range(
start: int | IntoExprColumn,
end: int | IntoExprColumn,
start: int | IntoExprColumn = ...,
end: int | IntoExprColumn | None = ...,
step: int = ...,
*,
dtype: PolarsIntegerType = ...,
Expand All @@ -131,8 +131,8 @@ def int_range(

@overload
def int_range(
start: int | IntoExprColumn,
end: int | IntoExprColumn,
start: int | IntoExprColumn = ...,
end: int | IntoExprColumn | None = ...,
step: int = ...,
*,
dtype: PolarsIntegerType = ...,
Expand All @@ -157,9 +157,8 @@ def int_range(
start
Start of the range (inclusive). Defaults to 0.
end
End of the range (exclusive).
If set to `None` (default), the value of `start` is used and `start` is set
to `0`.
End of the range (exclusive). If set to `None` (default),
the value of `start` is used and `start` is set to `0`.
step
Step size of the range.
dtype
Expand Down Expand Up @@ -188,12 +187,23 @@ def int_range(
2
]
`end` can be omitted for a shorter syntax.
>>> pl.int_range(3, eager=True).alias("int")
shape: (3,)
Series: 'int' [i64]
[
0
1
2
]
`int_range` can be used in conjunction with `count` to generate an index column
for a DataFrame.
>>> df = pl.DataFrame({"a": [1, 3, 5], "b": [2, 4, 6]})
>>> df.select(
... pl.int_range(0, pl.count(), dtype=pl.UInt32).alias("index"),
... pl.int_range(pl.count(), dtype=pl.UInt32).alias("index"),
... pl.all(),
... )
shape: (3, 3)
Expand Down Expand Up @@ -271,9 +281,9 @@ def int_ranges(
Parameters
----------
start
Lower bound of the range (inclusive).
Start of the range (inclusive).
end
Upper bound of the range (exclusive).
End of the range (exclusive).
step
Step size of the range.
dtype
Expand Down
12 changes: 12 additions & 0 deletions py-polars/tests/unit/functions/range/test_int_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ def test_int_range() -> None:
assert_series_equal(pl.select(int_range=result).to_series(), expected)


def test_int_range_short_syntax() -> None:
result = pl.int_range(3)
expected = pl.Series("int", [0, 1, 2])
assert_series_equal(pl.select(int=result).to_series(), expected)


def test_int_range_start_default() -> None:
result = pl.int_range(end=3)
expected = pl.Series("int", [0, 1, 2])
assert_series_equal(pl.select(int=result).to_series(), expected)


def test_int_range_eager() -> None:
result = pl.int_range(0, 3, eager=True)
expected = pl.Series("literal", [0, 1, 2])
Expand Down

0 comments on commit 503699c

Please sign in to comment.