Skip to content

Commit

Permalink
Add Support for Decimal as Input to arrow.get. (arrow-py#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
krisfremen committed Sep 5, 2021
1 parent 80e5947 commit 246c55d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions arrow/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import calendar
from datetime import date, datetime
from datetime import tzinfo as dt_tzinfo
from decimal import Decimal
from time import struct_time
from typing import Any, List, Optional, Tuple, Type, Union, overload

Expand Down Expand Up @@ -218,6 +219,8 @@ def get(self, *args: Any, **kwargs: Any) -> Arrow:

if arg_count == 1:
arg = args[0]
if isinstance(arg, Decimal):
arg = float(arg)

# (None) -> raises an exception
if arg is None:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
from datetime import date, datetime
from decimal import Decimal

import pytest
from dateutil import tz
Expand Down Expand Up @@ -263,6 +264,13 @@ def test_one_arg_bool(self):
with pytest.raises(TypeError):
self.factory.get(True)

def test_one_arg_decimal(self):
result = self.factory.get(Decimal(1577836800.26843))

assert result._datetime == datetime(
2020, 1, 1, 0, 0, 0, 268430, tzinfo=tz.tzutc()
)

def test_two_args_datetime_tzinfo(self):

result = self.factory.get(datetime(2013, 1, 1), tz.gettz("US/Pacific"))
Expand Down

0 comments on commit 246c55d

Please sign in to comment.