Skip to content

(r)true/floor div #764

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 11 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2277,10 +2277,10 @@ class DataFrame(NDFrame, OpsMixin):
) -> DataFrame | Series: ...
# floordiv overload
def __floordiv__(
self, other: float | DataFrame | Series[int] | Series[float]
self, other: float | DataFrame | Series[int] | Series[float] | Sequence[float]
) -> Self: ...
def __rfloordiv__(
self, other: float | DataFrame | Series[int] | Series[float]
self, other: float | DataFrame | Series[int] | Series[float] | Sequence[float]
) -> Self: ...
def __truediv__(self, other: float | DataFrame | Series) -> Self: ...
def __rtruediv__(self, other: float | DataFrame | Series) -> Self: ...
def __truediv__(self, other: float | DataFrame | Series | Sequence) -> Self: ...
def __rtruediv__(self, other: float | DataFrame | Series | Sequence) -> Self: ...
36 changes: 30 additions & 6 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2028,19 +2028,43 @@ class TimedeltaSeries(Series[Timedelta]):
self, other: Timedelta | TimedeltaSeries | TimedeltaIndex | np.timedelta64
) -> TimedeltaSeries: ...
@overload # type: ignore[override]
def __truediv__(self, other: float) -> Self: ...
def __truediv__(self, other: float | Sequence[float]) -> Self: ...
@overload
def __truediv__(
self, other: timedelta | TimedeltaSeries | np.timedelta64 | TimedeltaIndex
self,
other: timedelta
| TimedeltaSeries
| np.timedelta64
| TimedeltaIndex
| Sequence[timedelta],
) -> Series[float]: ...
def __rtruediv__( # type: ignore[override]
self,
other: timedelta
| TimedeltaSeries
| np.timedelta64
| TimedeltaIndex
| Sequence[timedelta],
) -> Series[float]: ...
def __rtruediv__(self, other: timedelta | TimedeltaSeries | np.timedelta64 | TimedeltaIndex) -> Series[float]: ... # type: ignore[override,misc]
@overload # type: ignore[override]
def __floordiv__(self, other: float) -> Self: ...
def __floordiv__(self, other: float | Sequence[float]) -> Self: ...
@overload
def __floordiv__(
self, other: timedelta | TimedeltaSeries | np.timedelta64 | TimedeltaIndex
self,
other: timedelta
| TimedeltaSeries
| np.timedelta64
| TimedeltaIndex
| Sequence[timedelta],
) -> Series[int]: ...
def __rfloordiv__( # type: ignore[override]
self,
other: timedelta
| TimedeltaSeries
| np.timedelta64
| TimedeltaIndex
| Sequence[timedelta],
) -> Series[int]: ...
def __rfloordiv__(self, other: timedelta | TimedeltaSeries | np.timedelta64 | TimedeltaIndex) -> Series[int]: ... # type: ignore[override,misc]
@property
def dt(self) -> TimedeltaProperties: ... # type: ignore[override]
def mean( # type: ignore[override]
Expand Down
11 changes: 2 additions & 9 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import datetime as dt
from typing import (
TYPE_CHECKING,
Tuple,
Union,
)
Expand All @@ -12,7 +11,6 @@
import pandas as pd
from typing_extensions import (
Never,
TypeAlias,
assert_type,
)

Expand All @@ -23,11 +21,6 @@
check,
)

if TYPE_CHECKING:
from pandas.core.indexes.timedeltas import TimedeltaIndex
else:
TimedeltaIndex: TypeAlias = pd.Index


def test_index_unique() -> None:
df = pd.DataFrame({"x": [1, 2, 3, 4]}, index=pd.Index([1, 2, 3, 2]))
Expand Down Expand Up @@ -1036,9 +1029,9 @@ def test_timedelta_div() -> None:
delta = dt.timedelta(1)

check(assert_type(index / delta, "pd.Index[float]"), pd.Index, float)
check(assert_type(index / 1, "TimedeltaIndex"), pd.Index, pd.Timedelta)
check(assert_type(index / 1, "pd.TimedeltaIndex"), pd.TimedeltaIndex, pd.Timedelta)
check(assert_type(index // delta, "pd.Index[int]"), pd.Index, np.longlong)
check(assert_type(index // 1, "TimedeltaIndex"), pd.Index, pd.Timedelta)
check(assert_type(index // 1, "pd.TimedeltaIndex"), pd.TimedeltaIndex, pd.Timedelta)

check(assert_type(delta / index, "pd.Index[float]"), pd.Index, float)
check(assert_type(delta // index, "pd.Index[int]"), pd.Index, np.longlong)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2693,13 +2693,21 @@ def test_timedelta_div() -> None:
delta = datetime.timedelta(1)

check(assert_type(series / delta, "pd.Series[float]"), pd.Series, float)
check(assert_type(series / [delta], "pd.Series[float]"), pd.Series, float)
check(assert_type(series / 1, "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(series / [1], "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(series // delta, "pd.Series[int]"), pd.Series, np.longlong)
check(assert_type(series // [delta], "pd.Series[int]"), pd.Series, int)
check(assert_type(series // 1, "TimedeltaSeries"), pd.Series, pd.Timedelta)
check(assert_type(series // [1], "TimedeltaSeries"), pd.Series, pd.Timedelta)

check(assert_type(delta / series, "pd.Series[float]"), pd.Series, float)
check(assert_type([delta] / series, "pd.Series[float]"), pd.Series, float)
check(assert_type(delta // series, "pd.Series[int]"), pd.Series, np.longlong)
check(assert_type([delta] // series, "pd.Series[int]"), pd.Series, np.int64)

if TYPE_CHECKING_INVALID_USAGE:
1 / series # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
[1] / series # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
1 // series # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
[1] // series # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]