Skip to content

Commit 8945eaa

Browse files
HasanAhmadQ7HasanAhmadQ7
HasanAhmadQ7
authored and
HasanAhmadQ7
committed
BUG: .sel method gives error when label is float different from coords float type
generalizing to coerce not only scalar/lists float but also numpy arrays
1 parent 0f39a30 commit 8945eaa

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

xarray/core/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def remap_label_indexers(data_obj, indexers, method=None, tolerance=None):
249249
'an associated coordinate.')
250250
pos_indexers[dim] = label
251251
else:
252-
coords_dtype = data_obj.coords[dim].values.dtype
252+
coords_dtype = data_obj.coords[dim].dtype
253253
label = maybe_cast_to_coords_dtype(label, coords_dtype)
254254
idxr, new_idx = convert_label_indexer(index, label,
255255
dim, method, tolerance)

xarray/core/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ def _maybe_cast_to_cftimeindex(index: pd.Index) -> pd.Index:
6767

6868

6969
def maybe_cast_to_coords_dtype(label, coords_dtype):
70-
if isinstance(label, float):
71-
label = coords_dtype.type(label)
72-
elif isinstance(label, list) and coords_dtype.kind == 'f':
70+
if coords_dtype.kind == 'f' and not isinstance(label, slice):
7371
label = np.asarray(label, dtype=coords_dtype)
7472
return label
7573

0 commit comments

Comments
 (0)