From bd6f6d39a39bc36e5fb3cb37df0120ac49cc3934 Mon Sep 17 00:00:00 2001 From: Dennis Tai Date: Sun, 7 Jul 2024 23:17:50 -0700 Subject: [PATCH] Quick fix To allow is_ordered_datetime() to handle tz-aware vectors, use pandas.to_series().diff() --- orbit/utils/general.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/orbit/utils/general.py b/orbit/utils/general.py index cb7d15f4..3d467687 100644 --- a/orbit/utils/general.py +++ b/orbit/utils/general.py @@ -14,8 +14,13 @@ 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. + """ + diff = array.to_series().diff().dropna().values + return np.all(diff.astype(float) > 0) def is_even_gap_datetime(array):