MCPcopy
hub / github.com/pandas-dev/pandas / _unconvert_string_array

Function _unconvert_string_array

pandas/io/pytables.py:5331–5370  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

5329
5330
5331def _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
5373def _maybe_convert(values: np.ndarray, val_kind: str, encoding: str, errors: str):

Callers 3

convertMethod · 0.85
_unconvert_indexFunction · 0.85
_get_converterFunction · 0.85

Calls 6

SeriesClass · 0.90
decodeMethod · 0.80
ravelMethod · 0.45
to_numpyMethod · 0.45
astypeMethod · 0.45
reshapeMethod · 0.45

Tested by

no test coverage detected