-
-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1c98e9e
commit af6d7c5
Showing
5 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
## drift | ||
|
||
- Added `FHDDM` drift detector. | ||
- Added `FHDDM` drift detector. | ||
- Added a `iter_polars` function to iterate over the rows of a polars DataFrame. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import annotations | ||
|
||
import polars as pl | ||
|
||
from river import base, stream | ||
|
||
|
||
def iter_polars( | ||
X: pl.DataFrame, y: pl.Series | pl.DataFrame | None = None, **kwargs | ||
) -> base.typing.Stream: | ||
"""Iterates over the rows of a `polars.DataFrame`. | ||
Parameters | ||
---------- | ||
X | ||
A dataframe of features. | ||
y | ||
A series or a dataframe with one column per target. | ||
kwargs | ||
Extra keyword arguments are passed to the underlying call to `stream.iter_array`. | ||
Examples | ||
-------- | ||
>>> import polars as pl | ||
>>> from river import stream | ||
>>> X = pl.DataFrame({ | ||
... 'x1': [1, 2, 3, 4], | ||
... 'x2': ['blue', 'yellow', 'yellow', 'blue'], | ||
... 'y': [True, False, False, True] | ||
... }) | ||
>>> y = X.get_column('y') | ||
>>> X=X.drop("y") | ||
>>> for xi, yi in stream.iter_polars(X, y): | ||
... print(xi, yi) | ||
{'x1': 1, 'x2': 'blue'} True | ||
{'x1': 2, 'x2': 'yellow'} False | ||
{'x1': 3, 'x2': 'yellow'} False | ||
{'x1': 4, 'x2': 'blue'} True | ||
""" | ||
|
||
kwargs["feature_names"] = X.columns | ||
if isinstance(y, pl.DataFrame): | ||
kwargs["target_names"] = y.columns | ||
|
||
yield from stream.iter_array(X=X.to_numpy(), y=y if y is None else y.to_numpy(), **kwargs) |