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

Function maybe_coerce_to_str

xarray/core/utils.py:207–222  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

205
206
207def 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
225def maybe_wrap_array(original, new_array):

Callers 1

concatMethod · 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…