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

Function timestamp_as_unit

xarray/compat/pdcompat.py:76–87  ·  view source on GitHub ↗

Convert the underlying int64 representation to the given unit. Compatibility function for pandas issue where "as_unit" is not defined for pandas.Timestamp in pandas versions < 2.2. Can be removed minimum pandas version is >= 2.2.

(date: pd.Timestamp, unit: PDDatetimeUnitOptions)

Source from the content-addressed store, hash-verified

74
75
76def timestamp_as_unit(date: pd.Timestamp, unit: PDDatetimeUnitOptions) -> pd.Timestamp:
77 """Convert the underlying int64 representation to the given unit.
78
79 Compatibility function for pandas issue where "as_unit" is not defined
80 for pandas.Timestamp in pandas versions < 2.2. Can be removed minimum
81 pandas version is >= 2.2.
82 """
83 if hasattr(date, "as_unit"):
84 date = date.as_unit(unit)
85 elif hasattr(date, "_as_unit"):
86 date = date._as_unit(unit)
87 return date
88
89
90def default_precision_timestamp(*args, **kwargs) -> pd.Timestamp:

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…