MCPcopy Index your code
hub / github.com/pydata/xarray / CharacterArrayCoder

Class CharacterArrayCoder

xarray/coding/strings.py:154–174  ·  view source on GitHub ↗

Transforms between arrays containing bytes and character arrays.

Source from the content-addressed store, hash-verified

152
153
154class CharacterArrayCoder(VariableCoder):
155 """Transforms between arrays containing bytes and character arrays."""
156
157 def encode(self, variable, name=None):
158 variable = ensure_fixed_length_bytes(variable)
159
160 dims, data, attrs, encoding = unpack_for_encoding(variable)
161 if data.dtype.kind == "S" and encoding.get("dtype") is not str:
162 data = bytes_to_char(data)
163 char_dim_name = validate_char_dim_name(data.shape[-1], encoding, name)
164 dims = dims + (char_dim_name,)
165 return Variable(dims, data, attrs, encoding)
166
167 def decode(self, variable, name=None):
168 dims, data, attrs, encoding = unpack_for_decoding(variable)
169
170 if data.dtype == "S1" and dims:
171 encoding["char_dim_name"] = dims[-1]
172 dims = dims[:-1]
173 data = char_to_bytes(data)
174 return Variable(dims, data, attrs, encoding)
175
176
177def bytes_to_char(arr):

Callers 1

_encode_nc4_variableFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…