Skip to content

Commit

Permalink
UPDATE: enable np.array for benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekWadinger committed May 29, 2024
1 parent f88ba4c commit caaa432
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions river/preprocessing/hankel.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ def __init__(
self.n_features_in_: int

def learn_one(self, x: dict):
if not hasattr(self, "feature_names_in_"):
if not hasattr(self, "feature_names_in_") and isinstance(x, dict):
self.feature_names_in_ = list(x.keys())
self.n_features_in_ = len(x)
else:
assert self.feature_names_in_ == list(x.keys())

self._window.append(x)

def transform_one(self, x: dict):
if not isinstance(x, dict):
on_arrays = True
else:
on_arrays = False
# TODO: If called before learn_one, creates duplicate sample
_window = list(self._window)
w_past_current = len(_window)
Expand All @@ -88,6 +90,11 @@ def transform_one(self, x: dict):
if not self.return_partial == "copy":
for i in range(n_missing):
_window[i] = {k: float("nan") for k in _window[0]}
if on_arrays:
import numpy as np

return np.array([v for d in _window for v in d])
else:
return {
f"{k}_{i}": v
for i, d in enumerate(_window)
Expand Down

0 comments on commit caaa432

Please sign in to comment.