(self, variable: Variable, name: T_Name = None)
| 627 | """Encode NonString variables if dtypes differ.""" |
| 628 | |
| 629 | def encode(self, variable: Variable, name: T_Name = None) -> Variable: |
| 630 | if "dtype" in variable.encoding and variable.encoding["dtype"] not in ( |
| 631 | "S1", |
| 632 | str, |
| 633 | ): |
| 634 | dims, data, attrs, encoding = unpack_for_encoding(variable) |
| 635 | dtype = np.dtype(encoding.pop("dtype")) |
| 636 | if dtype != variable.dtype: |
| 637 | if np.issubdtype(dtype, np.integer): |
| 638 | if ( |
| 639 | np.issubdtype(variable.dtype, np.floating) |
| 640 | and "_FillValue" not in variable.attrs |
| 641 | and "missing_value" not in variable.attrs |
| 642 | ): |
| 643 | warnings.warn( |
| 644 | f"saving variable {name} with floating " |
| 645 | "point data as an integer dtype without " |
| 646 | "any _FillValue to use for NaNs", |
| 647 | SerializationWarning, |
| 648 | stacklevel=10, |
| 649 | ) |
| 650 | data = duck_array_ops.round(data) |
| 651 | data = duck_array_ops.astype(data, dtype=dtype) |
| 652 | return Variable(dims, data, attrs, encoding, fastpath=True) |
| 653 | else: |
| 654 | return variable |
| 655 | |
| 656 | def decode(self): |
| 657 | raise NotImplementedError() |
nothing calls this directly
no test coverage detected