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

Function _cast_timestamp_to_coarsest_resolution

xarray/coding/times.py:298–310  ·  view source on GitHub ↗
(timestamp: pd.Timestamp)

Source from the content-addressed store, hash-verified

296
297
298def _cast_timestamp_to_coarsest_resolution(timestamp: pd.Timestamp) -> pd.Timestamp:
299 # Cast timestamp to the coarsest resolution that can be used without
300 # changing its value. If provided a string, the pandas.Timestamp
301 # constructor used to automatically infer this from the resolution of the
302 # string, but this behavior was changed in pandas-dev/pandas#62801. This
303 # function allows us to approximately restore the old behavior in a way
304 # that is perhaps more consistent with how we infer the resolution of the
305 # data values themselves.
306 for unit in _ORDERED_PANDAS_TIME_RESOLUTIONS:
307 coarsest_timestamp = timestamp.as_unit(unit)
308 if coarsest_timestamp == timestamp:
309 return coarsest_timestamp
310 return timestamp
311
312
313def _unpack_time_unit_and_ref_date(

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…