Skip to content

Catch non-ValueError exceptions in decimal#636

Merged
pganssle merged 1 commit into
dateutil:masterfrom
pganssle:decimal_conversion
Mar 13, 2018
Merged

Catch non-ValueError exceptions in decimal#636
pganssle merged 1 commit into
dateutil:masterfrom
pganssle:decimal_conversion

Conversation

@pganssle

Copy link
Copy Markdown
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
Copy Markdown
Member Author

@amureki Looks good?

@amureki amureki left a comment

Copy link
Copy Markdown

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.

# 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?

@amureki amureki Mar 13, 2018

Copy link
Copy Markdown

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
Copy Markdown
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