(self, variable: Variable, name: T_Name = None)
| 1381 | self.time_unit = time_unit |
| 1382 | |
| 1383 | def encode(self, variable: Variable, name: T_Name = None) -> Variable: |
| 1384 | if np.issubdtype(variable.dtype, np.datetime64) or contains_cftime_datetimes( |
| 1385 | variable |
| 1386 | ): |
| 1387 | dims, data, attrs, encoding = unpack_for_encoding(variable) |
| 1388 | |
| 1389 | units = encoding.pop("units", None) |
| 1390 | calendar = encoding.pop("calendar", None) |
| 1391 | dtype = encoding.get("dtype", None) |
| 1392 | |
| 1393 | # in the case of packed data we need to encode into |
| 1394 | # float first, the correct dtype will be established |
| 1395 | # via CFScaleOffsetCoder/CFMaskCoder |
| 1396 | if "add_offset" in encoding or "scale_factor" in encoding: |
| 1397 | dtype = data.dtype if data.dtype.kind == "f" else "float64" |
| 1398 | (data, units, calendar) = encode_cf_datetime(data, units, calendar, dtype) |
| 1399 | |
| 1400 | safe_setitem(attrs, "units", units, name=name) |
| 1401 | safe_setitem(attrs, "calendar", calendar, name=name) |
| 1402 | |
| 1403 | return Variable(dims, data, attrs, encoding, fastpath=True) |
| 1404 | else: |
| 1405 | return variable |
| 1406 | |
| 1407 | def decode(self, variable: Variable, name: T_Name = None) -> Variable: |
| 1408 | units = variable.attrs.get("units", None) |
nothing calls this directly
no test coverage detected