Skip to content
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

Fix to account for various different array types #876

Merged
merged 1 commit into from
Jul 10, 2024
Merged
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
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
Loading