Inverse of _convert_string_array. Parameters ---------- data : np.ndarray[fixed-length-string] nan_rep : the storage repr of NaN encoding : str errors : str Handler for encoding errors. Returns ------- np.ndarray[object] Decoded data.
(
data: np.ndarray, nan_rep, encoding: str, errors: str
)
| 5329 | |
| 5330 | |
| 5331 | def _unconvert_string_array( |
| 5332 | data: np.ndarray, nan_rep, encoding: str, errors: str |
| 5333 | ) -> np.ndarray: |
| 5334 | """ |
| 5335 | Inverse of _convert_string_array. |
| 5336 | |
| 5337 | Parameters |
| 5338 | ---------- |
| 5339 | data : np.ndarray[fixed-length-string] |
| 5340 | nan_rep : the storage repr of NaN |
| 5341 | encoding : str |
| 5342 | errors : str |
| 5343 | Handler for encoding errors. |
| 5344 | |
| 5345 | Returns |
| 5346 | ------- |
| 5347 | np.ndarray[object] |
| 5348 | Decoded data. |
| 5349 | """ |
| 5350 | shape = data.shape |
| 5351 | data = np.asarray(data.ravel(), dtype=object) |
| 5352 | |
| 5353 | if len(data): |
| 5354 | itemsize = libwriters.max_len_string_array(ensure_object(data)) |
| 5355 | dtype = f"U{itemsize}" |
| 5356 | |
| 5357 | if isinstance(data[0], bytes): |
| 5358 | ser = Series(data, copy=False).str.decode( |
| 5359 | encoding, errors=errors, dtype="object" |
| 5360 | ) |
| 5361 | data = ser.to_numpy() |
| 5362 | data.flags.writeable = True |
| 5363 | else: |
| 5364 | data = data.astype(dtype, copy=False).astype(object, copy=False) |
| 5365 | |
| 5366 | if nan_rep is None: |
| 5367 | nan_rep = "nan" |
| 5368 | |
| 5369 | libwriters.string_array_replace_from_nan_rep(data, nan_rep) |
| 5370 | return data.reshape(shape) |
| 5371 | |
| 5372 | |
| 5373 | def _maybe_convert(values: np.ndarray, val_kind: str, encoding: str, errors: str): |