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 4 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
12 changes: 7 additions & 5 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import datetime as dt
import sys
from typing import (
Tuple,
Union,
Expand Down Expand Up @@ -1025,7 +1026,7 @@ def test_new() -> None:


def test_timedelta_div() -> None:
index = pd.Index([pd.Timedelta(1)], dtype="timedelta64[s]")
index = pd.Index([pd.Timedelta(days=1)], dtype="timedelta64[s]")
delta = dt.timedelta(1)

check(assert_type(index / delta, "pd.Index[float]"), pd.Index, float)
Expand All @@ -1038,11 +1039,12 @@ def test_timedelta_div() -> None:
check(assert_type(index // [1], pd.TimedeltaIndex), pd.TimedeltaIndex, pd.Timedelta)

check(assert_type(delta / index, "pd.Index[float]"), pd.Index, float)
# ZeroDivisionError
# check(assert_type([delta] / index, "pd.Index[float]"), pd.Index, float)
check(assert_type([delta] / index, "pd.Index[float]"), pd.Index, float)
check(assert_type(delta // index, "pd.Index[int]"), pd.Index, np.longlong)
# ZeroDivisionError
# check(assert_type([delta] // index, "pd.Index[int]"), pd.Index, np.longlong)
dtype: type[np.integer] = np.int64
if sys.platform == "win32":
dtype = np.int32
check(assert_type([delta] // index, "pd.Index[int]"), pd.Index, dtype)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use np.intp and it will be platform independent. Did you try that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try np.integer ? Both isinstance(np.int32(8), np.integer) and isinstance(np.int64(10), np.integer) are True for me on Windows and Linux.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, using np.signedinteger worked as well :)


if TYPE_CHECKING_INVALID_USAGE:
1 / index # type: ignore[operator] # pyright: ignore[reportGeneralTypeIssues]
Expand Down
8 changes: 6 additions & 2 deletions tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path
import platform
import re
import sys
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -2689,7 +2690,7 @@ def double(x):


def test_timedelta_div() -> None:
series = pd.Series([pd.Timedelta(1)])
series = pd.Series([pd.Timedelta(days=1)])
delta = datetime.timedelta(1)

check(assert_type(series / delta, "pd.Series[float]"), pd.Series, float)
Expand All @@ -2704,7 +2705,10 @@ def test_timedelta_div() -> None:
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)
dtype: type[np.integer] = np.int64
if sys.platform == "win32":
dtype = np.int32
check(assert_type([delta] // series, "pd.Series[int]"), pd.Series, dtype)

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