Accept Decimal timestamps in fromtimestamp and utcfromtimestamp - #1340
Open
Nishuuzz wants to merge 1 commit into
Open
Accept Decimal timestamps in fromtimestamp and utcfromtimestamp#1340Nishuuzz wants to merge 1 commit into
Nishuuzz wants to merge 1 commit into
Conversation
`arrow.get()` takes a Decimal timestamp and has done since arrow-py#900, with a test covering it, because the factory converts one to a float before dispatching. The constructors it stands in for do not: >>> arrow.get(Decimal("1591328104.308505")) <Arrow [2020-06-05T03:35:04.308505+00:00]> >>> Arrow.utcfromtimestamp(Decimal("1591328104.308505")) ValueError: The provided timestamp Decimal('1591328104.308505') is invalid. They gate on util.is_timestamp, which only admits int, float and str, so a Decimal is turned away as invalid even though the following line calls float() on it and would have been perfectly happy. Convert it the same way the factory does, rather than widening is_timestamp, which two open pull requests are already changing.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1340 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 2315 2320 +5
Branches 358 360 +2
=========================================
+ Hits 2315 2320 +5 ☔ View full report in Codecov by Harness. |
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.
arrow.get()accepts aDecimaltimestamp, but the constructors it stands in for reject the same value:Same for
Arrow.fromtimestamp.The factory converts a
Decimalto afloatbefore dispatching, andtest_one_arg_decimalcovers it, so this is supported input rather than something that happens to work.fromtimestampandutcfromtimestampinstead gate onutil.is_timestamp, which only admitsint,floatandstr. ADecimalis turned away as "invalid" — and the very next line callsfloat(timestamp), which would have been perfectly happy with it.This converts it in those two methods, the same way the factory already does, and widens their type hints and docstrings to match.
I deliberately did not change
util.is_timestamp, even though that is where the check lives. #1321 and #1324 are both open against that function, and it is public API in its own right, so it seemed better to leave it alone and fix the asymmetry where it actually shows.Testing
test_fromtimestamp_decimalandtest_utcfromtimestamp_decimal, next to the existing tests for those constructors. Both fail on master with theValueErrorabove.Full suite is green at 1903 passed, and black and flake8 are clean. The existing
float,strand invalid-input behaviour is unchanged —"invalid timestamp"still raises, and the two existing assertions covering that still pass.