Repository navigation
Compare mixed Timestamp and float timestamps in the OpenMetrics parser - #1266
Open
amdadulbari wants to merge 1 commit into
Open
amdadulbari wants to merge 1 commit into
amdadulbari wants to merge 1 commit into
Conversation
_parse_timestamp returns a Timestamp for fixed-point values such as "1" or "1.5" and a float for exponent notation such as "1.5e0". When a group mixed the two, the "Timestamps went backwards" check compared them with Timestamp.__gt__/__lt__, which read .sec/.nsec from the float and raised AttributeError instead of parsing the input (or raising ValueError for timestamps that really went backwards). Compare two Timestamps exactly as before, and fall back to comparing float values when either side is a float. Signed-off-by: Md. Amdadul Bari Imad <amdadulbari@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@csmarchbanks
_parse_timestampreturns aTimestampfor fixed-point timestamps (1,2.5) and afloatfor exponent notation (1.5e0), both of which are valid OpenMetrics timestamps. When a group contains both forms, the "Timestamps went backwards" check compares them withTimestamp.__gt__/__lt__, which read.sec/.nsecfrom the float and raiseAttributeError:Input whose timestamps really go backwards (
a 0 2thena 0 1.5e0) also raisesAttributeErrorinstead of the expectedValueError.This change keeps the exact comparison when both values are
Timestamps and compares float values when either side is a float.Tests: added
test_mixed_timestamp_formats(ascending mixed-format timestamps parse) and two backwards mixed-format cases intest_invalid_input. Both fail withAttributeErrorwithout the fix; the full test suite, flake8, isort and mypy pass.