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

(r)true/floor div #764

merged 11 commits into from
Aug 16, 2023

Conversation

twoertwein
Copy link
Member

Focused mostly on timedelta.

@twoertwein twoertwein requested a review from Dr-Irv August 14, 2023 15:45
Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

I hit approve by mistake!

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

I think we can fix the div by zero problem.


check(assert_type(delta / index, "pd.Index[float]"), pd.Index, float)
# ZeroDivisionError
# check(assert_type([delta] / index, "pd.Index[float]"), pd.Index, float)
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 if you did index = pd.Index([pd.Timedelta(days=1)], dtype="timedelta64[s]"), then we wouldn't get the div by zero.

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, that made it work!

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 :)

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

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

Thanks @twoertwein

@Dr-Irv Dr-Irv merged commit 82f8994 into pandas-dev:main Aug 16, 2023
@twoertwein twoertwein deleted the div branch August 17, 2023 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants