8000 Catch non-ValueError exceptions in decimal by pganssle · Pull Request #636 · dateutil/dateutil · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Catch non-ValueError exceptions in decimal #636

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

Merged
merged 1 commit into from
Mar 13, 2018

Conversation

pganssle
Copy link
Member

Fixes #632.

This adds both function call overhead and exception catching overhead to the function. Based on running %timeit on a few strings, the cost is on the order of a few microseconds out of 60-100 microseconds. If we can come up with a version that doesn't have to re-raise, that might be preferable.

Also, we could theoretically add whatever errors Decimal is raising into the huge try-except loop and handle it that way, but the documentation doesn't seem to clearly enumerate an exception hierarchy for decimal.Decimal, so I'm not confident that we could catch the "root" exception easily.

@pganssle pganssle added this to the 2.7.1 milestone Mar 12, 2018
@pganssle pganssle force-pushed the decimal_conversion branch from b3410e1 to 5f2052f Compare March 12, 2018 17:19
@pganssle
Copy link
Member Author

@amureki Looks good?

Copy link
Contributor
@amureki amureki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it on our system, worked fine in previously broken cases. So it looks good to me! ✨
P.S. Small comment regarding TODO, but it is completely up to you.

@@ -895,7 +899,7 @@ def _parse_numeric_token(self, tokens, idx, info, ymd, res, fuzzy):
elif idx + 2 < len_l and tokens[idx + 1] == ':':
# HH:MM[:SS[.ss]]
res.hour = int(value)
value = Decimal(tokens[idx + 2]) # TODO: try/except for this?
value = self._to_decimal(tokens[idx + 2]) # TODO: try/except for this?
Copy link
Contributor
@amureki amureki Mar 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we remove TODO comment from here? Since we are covering this in _to_decimal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, _to_decimal can still raise a ValueError, and that TODO predates the switch to Decimal:

3b43612#diff-4b65e7edb2b73639d2d3360fa8d05343L935

That said, I don't really know what it refers to. I'll leave it in for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0