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

Function delta_to_tick

xarray/coding/cftime_offsets.py:800–821  ·  view source on GitHub ↗

Adapted from pandas.tslib.delta_to_tick

(delta: timedelta | pd.Timedelta)

Source from the content-addressed store, hash-verified

798
799
800def delta_to_tick(delta: timedelta | pd.Timedelta) -> Tick:
801 """Adapted from pandas.tslib.delta_to_tick"""
802 if isinstance(delta, pd.Timedelta) and delta.nanoseconds != 0:
803 # pandas.Timedelta has nanoseconds, but these are not supported
804 raise ValueError(
805 "Unable to convert 'pandas.Timedelta' object with non-zero "
806 "nanoseconds to 'CFTimeOffset' object"
807 )
808 if delta.microseconds == 0:
809 seconds = delta.days * 86400 + delta.seconds
810 if seconds % 3600 == 0:
811 return Hour(n=seconds // 3600)
812 elif seconds % 60 == 0:
813 return Minute(n=seconds // 60)
814 else:
815 return Second(n=seconds)
816 # Regardless of the days and seconds this will always be a Millisecond
817 # or Microsecond object
818 elif delta.microseconds % 1_000 == 0:
819 return Millisecond(n=delta.microseconds // 1_000)
820 else:
821 return Microsecond(n=delta.microseconds)
822
823
824def to_cftime_datetime(date_str_or_date, calendar=None):

Callers 1

to_offsetFunction · 0.85

Calls 5

HourClass · 0.85
MinuteClass · 0.85
SecondClass · 0.85
MillisecondClass · 0.85
MicrosecondClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…