diff options
author | Aki <please@ignore.pl> | 2022-10-07 23:14:23 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-10-07 23:14:23 +0200 |
commit | 91945e1b4ba9dd270475cc84675781ea26c0a8b7 (patch) | |
tree | c49299a29f01a6f3013d2eb4673c0d879e3c87fe | |
parent | 3d6ae44e4ff20d480aa080ec23cb7606ebfe55bc (diff) | |
download | windy-91945e1b4ba9dd270475cc84675781ea26c0a8b7.zip windy-91945e1b4ba9dd270475cc84675781ea26c0a8b7.tar.gz windy-91945e1b4ba9dd270475cc84675781ea26c0a8b7.tar.bz2 |
Removed iterator responsibility from Prediction
-rw-r--r-- | windy/point_forecast.py | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/windy/point_forecast.py b/windy/point_forecast.py index 5affd05..743d85f 100644 --- a/windy/point_forecast.py +++ b/windy/point_forecast.py @@ -87,33 +87,14 @@ class Request: class Prediction: """ - Allows to iterate over predicted values from the Response in a zip-like manner, where all parameters for a given - time point are available via item access. + Predicted values for each of the requested parameters along with their associated time point. """ def __init__(self, response, index=0): self._response = response self._index = index - def __iter__(self): - return self - - def __next__(self): - self._index += 1 - if not self: - raise StopIteration - return self - - def __bool__(self): - return self._index < len(self) - - def __len__(self): - return len(self._response) - @property - def timestamp(self): - """ - Datetime object representing timestamp of the current prediction. - """ + def timestamp(self) -> datetime: return self._response.timestamps[self._index] def __getitem__(self, key): @@ -152,9 +133,10 @@ class Response: def predictions(self) -> Prediction: """ - Helper iterator to go over the predicted values in a zip-like manner. + Yields Prediction for each time point available in this Response. """ - return Prediction(self) + for index in range(len(self.timestamps)): + yield Prediction(self, index) def __iter__(self): return self.predictions() |