summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--windy/point_forecast.py28
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()