From 476755d53701b886fb312dadb5f4aa92ed32fa6e Mon Sep 17 00:00:00 2001 From: Janghee Lee Date: Wed, 12 Feb 2020 17:24:17 +0900 Subject: [PATCH] EHN: fix unsigned int type problem of the result diff() An unexpected output type(float64) occurs to diff() when using uint type. So fix it by restoring original dtype after storing it Fixes #28909 --- pandas/core/algorithms.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 886b0a3c5fec1..189b2ca8cc8e1 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -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") @@ -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