From 320bc38add18531eca96b1323a5edc670b5795ef Mon Sep 17 00:00:00 2001 From: Dennis Tai Date: Tue, 9 Jul 2024 22:09:44 -0700 Subject: [PATCH] Fix to account for various different array types Function can now properly handle np.ndarray, pd.series, pd.datetimeindex --- orbit/utils/general.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/orbit/utils/general.py b/orbit/utils/general.py index cb7d15f4..1f4a0a06 100644 --- a/orbit/utils/general.py +++ b/orbit/utils/general.py @@ -14,8 +14,15 @@ def update_dict(original_dict, append_dict): def is_ordered_datetime(array): - """Returns True if array is ordered and non-repetitive""" - return np.all(np.diff(array).astype(float) > 0) + """Returns True if array is ordered and non-repetitive + Use pandas .diff() method to take care of both tz and non-tz series consistently + By default pandas .diff() would generate a NaT for the first period + instead of skipping like np.diff. So dropna() to remove. + """ + if isinstance(array, np.ndarray): + array = pd.Series(array) + diff = array.diff().dropna().values + return np.all(diff.astype(float) > 0) def is_even_gap_datetime(array):