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

Function to_floatable

xarray/computation/computation.py:940–952  ·  view source on GitHub ↗
(x: DataArray)

Source from the content-addressed store, hash-verified

938 return type(scalar)(1970, 1, 1)
939
940 def to_floatable(x: DataArray) -> DataArray:
941 if x.dtype.kind in "MO":
942 # datetimes (CFIndexes are object type)
943 offset = (
944 np.datetime64("1970-01-01") if x.dtype.kind == "M" else _cfoffset(x)
945 )
946 return x.copy(
947 data=datetime_to_numeric(x.data, offset=offset, datetime_unit="ns"),
948 )
949 elif x.dtype.kind == "m":
950 # timedeltas
951 return duck_array_ops.astype(x, dtype=float)
952 return x
953
954 if isinstance(data, Dataset):
955 return data.map(to_floatable)

Callers 1

_ensure_numericFunction · 0.85

Calls 4

datetime_to_numericFunction · 0.90
_cfoffsetFunction · 0.85
copyMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…