From 7c1bb8dffcfc2fba08b470676884200f035b5051 Mon Sep 17 00:00:00 2001 From: Justus Magin Date: Wed, 6 Dec 2023 18:58:46 +0100 Subject: [PATCH] explicitly skip using `__array_namespace__` for `numpy.ndarray` (#8526) * explicitly skip using `__array_namespace__` for `numpy.ndarray` * actually use the array in question --------- Co-authored-by: Deepak Cherian --- xarray/core/duck_array_ops.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py index 7f2b2ed85ee..84cfd7f6fdc 100644 --- a/xarray/core/duck_array_ops.py +++ b/xarray/core/duck_array_ops.py @@ -335,7 +335,10 @@ def fillna(data, other): def concatenate(arrays, axis=0): """concatenate() with better dtype promotion rules.""" - if hasattr(arrays[0], "__array_namespace__"): + # TODO: remove the additional check once `numpy` adds `concat` to its array namespace + if hasattr(arrays[0], "__array_namespace__") and not isinstance( + arrays[0], np.ndarray + ): xp = get_array_namespace(arrays[0]) return xp.concat(as_shared_dtype(arrays, xp=xp), axis=axis) return _concatenate(as_shared_dtype(arrays), axis=axis)