Skip to content

EHN: fix unsigned int type problem of the result diff() #31916

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,7 @@ def diff(arr, n: int, axis: int = 0, stacklevel=3):

is_timedelta = False
is_bool = False
original_dtype = np.dtype(dtype)
if needs_i8_conversion(arr):
dtype = np.float64
arr = arr.view("i8")
Expand Down Expand Up @@ -1928,6 +1929,7 @@ def diff(arr, n: int, axis: int = 0, stacklevel=3):
if is_timedelta:
out_arr = out_arr.astype("int64").view("timedelta64[ns]")

out_arr = out_arr.astype(original_dtype)
return out_arr


Expand Down