Given an array of datetimes, infer the CF calendar name
(dates)
| 750 | |
| 751 | |
| 752 | def infer_calendar_name(dates) -> CFCalendar: |
| 753 | """Given an array of datetimes, infer the CF calendar name""" |
| 754 | if is_np_datetime_like(dates.dtype): |
| 755 | return "proleptic_gregorian" |
| 756 | elif dates.dtype == np.dtype("O") and dates.size > 0: |
| 757 | # Logic copied from core.common.contains_cftime_datetimes. |
| 758 | if cftime is not None: |
| 759 | sample = np.asarray(dates).flat[0] |
| 760 | if is_duck_dask_array(sample): |
| 761 | sample = sample.compute() |
| 762 | if isinstance(sample, np.ndarray): |
| 763 | sample = sample.item() |
| 764 | if isinstance(sample, cftime.datetime): |
| 765 | return sample.calendar |
| 766 | |
| 767 | # Error raise if dtype is neither datetime or "O", if cftime is not importable, and if element of 'O' dtype is not cftime. |
| 768 | raise ValueError("Array does not contain datetime objects.") |
| 769 | |
| 770 | |
| 771 | def infer_datetime_units(dates) -> str: |
no test coverage detected
searching dependent graphs…