maybe coerce a pandas Index back to a numpy array of type str pd.Index uses object-dtype to store str - try to avoid this for coords
(index, original_coords)
| 205 | |
| 206 | |
| 207 | def maybe_coerce_to_str(index, original_coords): |
| 208 | """maybe coerce a pandas Index back to a numpy array of type str |
| 209 | |
| 210 | pd.Index uses object-dtype to store str - try to avoid this for coords |
| 211 | """ |
| 212 | from xarray.core import dtypes |
| 213 | |
| 214 | try: |
| 215 | result_type = dtypes.result_type(*original_coords) |
| 216 | except (TypeError, ValueError): |
| 217 | pass |
| 218 | else: |
| 219 | if result_type.kind in "SU": |
| 220 | index = np.asarray(index, dtype=result_type.type) |
| 221 | |
| 222 | return index |
| 223 | |
| 224 | |
| 225 | def maybe_wrap_array(original, new_array): |
no outgoing calls
no test coverage detected
searching dependent graphs…