MCPcopy
hub / github.com/pydata/xarray / infer_calendar_name

Function infer_calendar_name

xarray/coding/times.py:752–768  ·  view source on GitHub ↗

Given an array of datetimes, infer the CF calendar name

(dates)

Source from the content-addressed store, hash-verified

750
751
752def 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
771def infer_datetime_units(dates) -> str:

Callers 5

to_datetimeindexMethod · 0.90
calendarMethod · 0.90
calendarMethod · 0.90

Calls 4

is_np_datetime_likeFunction · 0.90
is_duck_dask_arrayFunction · 0.90
dtypeMethod · 0.45
computeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…