Skip to content
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

Change span_range typehint to allow Arrow #1149

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions arrow/arrow.py
Expand Up @@ -303,7 +303,9 @@ def utcfromtimestamp(cls, timestamp: Union[int, float, str]) -> "Arrow":
)

@classmethod
def fromdatetime(cls, dt: dt_datetime, tzinfo: Optional[TZ_EXPR] = None) -> "Arrow":
def fromdatetime(
cls, dt: Union["Arrow", dt_datetime], tzinfo: Optional[TZ_EXPR] = None
) -> "Arrow":
"""Constructs an :class:`Arrow <arrow.arrow.Arrow>` object from a ``datetime`` and
optional replacement timezone.

Expand All @@ -318,6 +320,10 @@ def fromdatetime(cls, dt: dt_datetime, tzinfo: Optional[TZ_EXPR] = None) -> "Arr
>>> arrow.Arrow.fromdatetime(dt)
<Arrow [2021-04-07T13:48:00-07:00]>

**NOTE**:
Although you can pass a :class:`Arrow <arrow.arrow.Arrow>`, doing so is not recommended
except for some cases where it simplifies handling both.

"""

if tzinfo is None:
Expand Down Expand Up @@ -635,8 +641,8 @@ def ceil(self, frame: _T_FRAMES) -> "Arrow":
def span_range(
cls,
frame: _T_FRAMES,
start: dt_datetime,
end: dt_datetime,
start: Union["Arrow", dt_datetime],
end: Union["Arrow", dt_datetime],
tz: Optional[TZ_EXPR] = None,
limit: Optional[int] = None,
bounds: _BOUNDS = "[)",
Expand All @@ -646,8 +652,8 @@ def span_range(
representing a series of timespans between two inputs.

:param frame: The timeframe. Can be any ``datetime`` property (day, hour, minute...).
:param start: A datetime expression, the start of the range.
:param end: (optional) A datetime expression, the end of the range.
:param start: A datetime or :class:`Arrow <arrow.arrow.Arrow>` expression, the start of the range.
:param end: (optional) A datetime or :class:`Arrow <arrow.arrow.Arrow>` expression, the end of the range.
:param tz: (optional) A :ref:`timezone expression <tz-expr>`. Defaults to
``start``'s timezone, or UTC if ``start`` is naive.
:param limit: (optional) A maximum number of tuples to return.
Expand Down