Skip to content

Commit

Permalink
Fix to account for various different array types
Browse files Browse the repository at this point in the history
Function can now properly handle np.ndarray, pd.series, pd.datetimeindex
  • Loading branch information
swotai authored and edwinnglabs committed Jul 10, 2024
1 parent 14fdb74 commit 08ee565
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions orbit/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 08ee565

Please sign in to comment.