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

Function _lazily_encode_cf_timedelta

xarray/coding/times.py:1328–1352  ·  view source on GitHub ↗
(
    timedeltas: T_ChunkedArray, units: str | None = None, dtype: np.dtype | None = None
)

Source from the content-addressed store, hash-verified

1326
1327
1328def _lazily_encode_cf_timedelta(
1329 timedeltas: T_ChunkedArray, units: str | None = None, dtype: np.dtype | None = None
1330) -> tuple[T_ChunkedArray, str]:
1331 if units is None and dtype is None:
1332 units = _numpy_dtype_to_netcdf_timeunit(timedeltas.dtype)
1333 dtype = np.dtype("int64")
1334
1335 if units is None or dtype is None:
1336 raise ValueError(
1337 f"When encoding chunked arrays of timedelta values, both the "
1338 f"units and dtype must be prescribed or both must be "
1339 f"unprescribed. Prescribing only one or the other is not "
1340 f"currently supported. Got a units encoding of {units} and a "
1341 f"dtype encoding of {dtype}."
1342 )
1343
1344 chunkmanager = get_chunked_array_type(timedeltas)
1345 num = chunkmanager.map_blocks(
1346 _encode_cf_timedelta_within_map_blocks,
1347 timedeltas,
1348 units,
1349 dtype,
1350 dtype=dtype,
1351 )
1352 return num, units
1353
1354
1355class CFDatetimeCoder(VariableCoder):

Callers 1

encode_cf_timedeltaFunction · 0.85

Calls 4

get_chunked_array_typeFunction · 0.90
dtypeMethod · 0.45
map_blocksMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…