Skip to content

GH - 624: date_range() now supports a unit keyword "s" , "ms" , "us" , or "ns" #734

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

Merged
merged 5 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pandas-stubs/core/indexes/datetimes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ from datetime import (
timedelta,
tzinfo,
)
from typing import overload
from typing import (
Literal,
overload,
)

import numpy as np
from pandas import (
Expand Down Expand Up @@ -104,6 +107,7 @@ def date_range(
normalize: bool = ...,
name: Hashable | None = ...,
inclusive: IntervalClosedType = ...,
unit: Literal["s", "ms", "us", "ns"] | None = ...,
) -> DatetimeIndex: ...
@overload
def bdate_range(
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ packages = [
[tool.poetry.dependencies]
python = ">=3.8"
types-pytz = ">= 2022.1.1"
numpy = ">=1.24.3"
numpy = "<=1.24.3"

[tool.poetry.dev-dependencies]
mypy = "1.3.0"
pandas = "2.0.2"
pyarrow = ">=10.0.1"
pytest = ">=7.1.2"
pyright = ">= 1.1.310"
pyright = "<= 1.1.313"
poethepoet = ">=0.16.5"
loguru = ">=0.6.0"
typing-extensions = ">=4.4.0"
Expand Down
31 changes: 31 additions & 0 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,3 +1177,34 @@ def test_weekofmonth_init():
),
pd.offsets.WeekOfMonth,
)


def test_date_range_unit():
check(
assert_type(
pd.date_range("1/1/2022", "2/1/2022", unit="s"),
pd.DatetimeIndex,
),
pd.DatetimeIndex,
)
check(
assert_type(
pd.date_range("1/1/2022", "2/1/2022", unit="ms"),
pd.DatetimeIndex,
),
pd.DatetimeIndex,
)
check(
assert_type(
pd.date_range("1/1/2022", "2/1/2022", unit="us"),
pd.DatetimeIndex,
),
pd.DatetimeIndex,
)
check(
assert_type(
pd.date_range("1/1/2022", "2/1/2022", unit="ns"),
pd.DatetimeIndex,
),
pd.DatetimeIndex,
)