Repository: stabacco/stake-python (language: python)

Issue:
Exception thrown if rating contains a blank 'pt_prior' field
When attempting to get the ratings for 'AAPL' today, I came across the above error. Specifically, I get:
```
pydantic.error_wrappers.ValidationError: 1 validation error for Rating
pt_prior
  value is not a valid float (type=type_error.float)
```
Debugging the data, it appears sometimes the JSON returns the key but with an empty value which I think is what is throwing the exception.
Adding the code below seems to fix things:
```
    pt_prior: Optional[float] = None
+    @pydantic.validator('pt_prior', pre=True)
+    def pt_prior_blank_string(value, field):
+        if value == "":
+            return None
+        return value
    url_calendar: Optional[str] = None
```
Hope this helps.

Thanks for all your hard work.


Discussion / hints:

Fix patch:
diff --git a/stake/ratings.py b/stake/ratings.py
index fbe69a0..855b88d 100644
--- a/stake/ratings.py
+++ b/stake/ratings.py
@@ -37,6 +37,12 @@ class Rating(pydantic.BaseModel):
     url_news: Optional[str] = None
     analyst_name: Optional[str] = None
 
+    @pydantic.validator("pt_prior", "rating_prior", pre=True)
+    def pt_prior_blank_string(value, field):
+        if value == "":
+            return None
+        return value
+
 
 class RatingsClient(BaseClient):
     """This client is in charge listing the experts' ratings for symbols."""


Test patch:
diff --git a/tests/fixtures/tests.test_ratings.test_list_ratings.json b/tests/fixtures/tests.test_ratings.test_list_ratings.json
index 97ff7a7..c6a4540 100644
--- a/tests/fixtures/tests.test_ratings.test_list_ratings.json
+++ b/tests/fixtures/tests.test_ratings.test_list_ratings.json
@@ -79,7 +79,7 @@
                         "rating_current": "Buy",
                         "pt_current": "310.0000",
                         "rating_prior": "",
-                        "pt_prior": "285.0000",
+                        "pt_prior": "",
                         "url_calendar": "https://www.benzinga.com/stock/MSFT/ratings",
                         "url_news": "https://www.benzinga.com/stock-articles/MSFT/analyst-ratings",
                         "analyst_name": "Gregg Moskowitz"