(var)
| 230 | |
| 231 | |
| 232 | def _force_native_endianness(var): |
| 233 | # possible values for byteorder are: |
| 234 | # = native |
| 235 | # < little-endian |
| 236 | # > big-endian |
| 237 | # | not applicable |
| 238 | # Below we check if the data type is not native or NA |
| 239 | if var.dtype.byteorder not in ["=", "|"]: |
| 240 | # if endianness is specified explicitly, convert to the native type |
| 241 | data = var.data.astype(var.dtype.newbyteorder("=")) |
| 242 | var = Variable(var.dims, data, var.attrs, var.encoding) |
| 243 | # if endian exists, remove it from the encoding. |
| 244 | var.encoding.pop("endian", None) |
| 245 | # check to see if encoding has a value for endian its 'native' |
| 246 | if var.encoding.get("endian", "native") != "native": |
| 247 | raise NotImplementedError( |
| 248 | "Attempt to write non-native endian type, " |
| 249 | "this is not supported by the netCDF4 " |
| 250 | "python library." |
| 251 | ) |
| 252 | return var |
| 253 | |
| 254 | |
| 255 | def _extract_nc4_variable_encoding( |
no test coverage detected
searching dependent graphs…