Skip to content
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

Merged
merged 6 commits into from
Aug 25, 2022
Merged

Conversation

Unique-Divine
Copy link
Member

  • test: all green w/ new binary
  • increment pyproject version for release
  • update changelog
  • feat: safely cast string fields in vpool all_pools

@Unique-Divine Unique-Divine changed the title cast str to float safely cast str to float safely | v0.3 Aug 25, 2022
@Unique-Divine Unique-Divine added the type: enhancement New feature or request label Aug 25, 2022
try:
number = float(number_str)
except:
number = float(0)
Copy link
Collaborator

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

Copy link
Collaborator

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

Copy link
Member Author

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

Copy link
Member Author

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

@matthiasmatt matthiasmatt merged commit 816f824 into master Aug 25, 2022
@matthiasmatt matthiasmatt deleted the cast-str-to-float-safely branch August 25, 2022 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants