Convert numpy/dask arrays from fixed width bytes to characters.
(arr)
| 175 | |
| 176 | |
| 177 | def bytes_to_char(arr): |
| 178 | """Convert numpy/dask arrays from fixed width bytes to characters.""" |
| 179 | if arr.dtype.kind != "S": |
| 180 | raise ValueError("argument must have a fixed-width bytes dtype") |
| 181 | |
| 182 | if is_chunked_array(arr): |
| 183 | chunkmanager = get_chunked_array_type(arr) |
| 184 | |
| 185 | return chunkmanager.map_blocks( |
| 186 | _numpy_bytes_to_char, |
| 187 | arr, |
| 188 | dtype="S1", |
| 189 | chunks=arr.chunks + ((arr.dtype.itemsize,)), |
| 190 | new_axis=[arr.ndim], |
| 191 | ) |
| 192 | return _numpy_bytes_to_char(arr) |
| 193 | |
| 194 | |
| 195 | def _numpy_bytes_to_char(arr): |
no test coverage detected
searching dependent graphs…