(
timedeltas: T_ChunkedArray, units: str | None = None, dtype: np.dtype | None = None
)
| 1326 | |
| 1327 | |
| 1328 | def _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 | |
| 1355 | class CFDatetimeCoder(VariableCoder): |
no test coverage detected
searching dependent graphs…