-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cast str to float safely | v0.3 #111
Conversation
Unique-Divine
commented
Aug 25, 2022
- test: all green w/ new binary
- increment pyproject version for release
- update changelog
- feat: safely cast string fields in vpool all_pools
try: | ||
number = float(number_str) | ||
except: | ||
number = float(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need numpy np.nan there?
I was doing this just now:
# The golang application is returning index price and twap price as string since v0.14.0
# This is because those fields can be null, which leads to empty strings returned which cannot be easily
# deserialized automatically by the deserialized function inside the self.query call above.
# For this reason we do this manual update there
for _, price in enumerate(resp["prices"]):
for field in ["twap_mark", "index_price"]:
value = price[field]
if isinstance(value, str) and value == "":
value = np.nan
else:
value = float(value)
price[field] = value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually it's better to not have all the numpy dependency and reqs for the docker build we make
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same idea. I wasn't sure if we should add the numpy dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And both ""
and None
are invalid inputs to the float()
function, so it handles both cases