Skip to content

Commit d8367b2

Browse files
committed
Replace more usages of np.any with duck array ops equivalent
1 parent fda6a5b commit d8367b2

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

xarray/coding/times.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
)
2323
from xarray.core import indexing
2424
from xarray.core.common import contains_cftime_datetimes, is_np_datetime_like
25-
from xarray.core.duck_array_ops import array_all, asarray, ravel, reshape
25+
from xarray.core.duck_array_ops import array_all, array_any, asarray, ravel, reshape
2626
from xarray.core.formatting import first_n_items, format_timestamp, last_item
2727
from xarray.core.pdcompat import nanosecond_precision_timestamp, timestamp_as_unit
2828
from xarray.core.utils import attempt_import, emit_user_level_warning
@@ -824,7 +824,7 @@ def _cast_to_dtype_if_safe(num: np.ndarray, dtype: np.dtype) -> np.ndarray:
824824
"a larger integer dtype."
825825
)
826826
else:
827-
if np.isinf(cast_num).any():
827+
if array_any(np.isinf(cast_num)):
828828
raise OverflowError(
829829
f"Not possible to cast encoded times from {num.dtype!r} to "
830830
f"{dtype!r} without overflow. Consider removing the dtype "

xarray/core/formatting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from pandas.errors import OutOfBoundsDatetime
1919

2020
from xarray.core.datatree_render import RenderDataTree
21-
from xarray.core.duck_array_ops import array_all, array_equiv, astype
21+
from xarray.core.duck_array_ops import array_all, array_any, array_equiv, astype
2222
from xarray.core.indexing import MemoryCachedArray
2323
from xarray.core.options import OPTIONS, _get_boolean_with_default
2424
from xarray.core.treenode import group_subtrees
@@ -232,7 +232,7 @@ def format_array_flat(array, max_width: int):
232232

233233
cum_len = np.cumsum([len(s) + 1 for s in relevant_items]) - 1
234234
if (array.size > 2) and (
235-
(max_possibly_relevant < array.size) or (cum_len > max_width).any()
235+
(max_possibly_relevant < array.size) or array_any(cum_len > max_width)
236236
):
237237
padding = " ... "
238238
max_len = max(int(np.argmax(cum_len + len(padding) - 1 > max_width)), 2)

xarray/core/nanops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _nan_argminmax_object(func, fill_value, value, axis=None, **kwargs):
4545
data = getattr(np, func)(value, axis=axis, **kwargs)
4646

4747
# TODO This will evaluate dask arrays and might be costly.
48-
if (valid_count == 0).any():
48+
if duck_array_ops.array_any(valid_count == 0):
4949
raise ValueError("All-NaN slice encountered")
5050

5151
return data

0 commit comments

Comments
 (0)