Skip to content

Commit c5ae488

Browse files
mathausemax-sixty
andauthored
typing for numpy 1.21 (#5522)
* typing for numpy 1.21 * Update xarray/core/computation.py Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com> Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
1 parent eb906a4 commit c5ae488

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

xarray/core/accessor_str.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,10 @@ def _re_compile(
270270

271271
if getattr(pat, "dtype", None) != np.object_:
272272
pat = self._stringify(pat)
273-
func = lambda x: re.compile(x, flags=flags)
273+
274+
def func(x):
275+
return re.compile(x, flags=flags)
276+
274277
if isinstance(pat, np.ndarray):
275278
# apply_ufunc doesn't work for numpy arrays with output object dtypes
276279
func = np.vectorize(func)

xarray/core/computation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def broadcast_compat_data(
597597
data = duck_array_ops.transpose(data, order)
598598

599599
if new_dims != reordered_dims:
600-
key_parts = []
600+
key_parts: List[Optional[slice]] = []
601601
for dim in new_dims:
602602
if dim in set_old_dims:
603603
key_parts.append(SLICE_NONE)

xarray/core/formatting.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def format_array_flat(array, max_width: int):
190190
(max_possibly_relevant < array.size) or (cum_len > max_width).any()
191191
):
192192
padding = " ... "
193-
max_len = max(np.argmax(cum_len + len(padding) - 1 > max_width), 2) # type: ignore[type-var]
193+
max_len = max(int(np.argmax(cum_len + len(padding) - 1 > max_width)), 2) # type: ignore[type-var]
194194
count = min(array.size, max_len)
195195
else:
196196
count = array.size

xarray/core/indexes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def __init__(
163163
else:
164164
dtype_ = array.dtype
165165
else:
166-
dtype_ = np.dtype(dtype)
166+
dtype_ = np.dtype(dtype) # type: ignore[assignment]
167167
self._dtype = dtype_
168168

169169
def to_pandas_index(self) -> pd.Index:

0 commit comments

Comments
 (0)