From 1cdc9a8f72e41c21c44187701d74133d8ee58412 Mon Sep 17 00:00:00 2001 From: Cameron Blocker Date: Sun, 12 Jul 2020 03:38:37 -0400 Subject: BUG: fix mgrid output for lower precision float inputs Floats besides float64 were being coerced to integers and complex step sizes for the index trick classes would fail for complex64 input. Fixes #16466 --- numpy/lib/index_tricks.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'numpy/lib/index_tricks.py') diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py index e86c7a7bb..8a73e35ed 100644 --- a/numpy/lib/index_tricks.py +++ b/numpy/lib/index_tricks.py @@ -154,15 +154,15 @@ class nd_grid: start = 0 if step is None: step = 1 - if isinstance(step, complex): + if isinstance(step, (_nx.complexfloating, complex)): size.append(int(abs(step))) typ = float else: size.append( int(math.ceil((key[k].stop - start)/(step*1.0)))) - if (isinstance(step, float) or - isinstance(start, float) or - isinstance(key[k].stop, float)): + if (isinstance(step, (_nx.floating, float)) or + isinstance(start, (_nx.floating, float)) or + isinstance(key[k].stop, (_nx.floating, float))): typ = float if self.sparse: nn = [_nx.arange(_x, dtype=_t) @@ -176,7 +176,7 @@ class nd_grid: start = 0 if step is None: step = 1 - if isinstance(step, complex): + if isinstance(step, (_nx.complexfloating, complex)): step = int(abs(step)) if step != 1: step = (key[k].stop - start)/float(step-1) @@ -194,7 +194,7 @@ class nd_grid: start = key.start if start is None: start = 0 - if isinstance(step, complex): + if isinstance(step, (_nx.complexfloating, complex)): step = abs(step) length = int(step) if step != 1: @@ -344,7 +344,7 @@ class AxisConcatenator: start = 0 if step is None: step = 1 - if isinstance(step, complex): + if isinstance(step, (_nx.complexfloating, complex)): size = int(abs(step)) newobj = linspace(start, stop, num=size) else: -- cgit v1.2.1 From d67326db34d6268b0deeb61f71a57062ab0d7c4d Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 30 Jul 2020 22:46:56 -0700 Subject: DOC: update val to be scalar or array like optional closes #16901 (#16907) * DOC: update val to be scalar or array like optional closes #16901 Co-authored-by: Ross Barnowski --- numpy/lib/index_tricks.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'numpy/lib/index_tricks.py') diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py index 2833e1072..6093f7e9d 100644 --- a/numpy/lib/index_tricks.py +++ b/numpy/lib/index_tricks.py @@ -769,9 +769,11 @@ def fill_diagonal(a, val, wrap=False): a : array, at least 2-D. Array whose diagonal is to be filled, it gets modified in-place. - val : scalar - Value to be written on the diagonal, its type must be compatible with - that of the array a. + val : scalar or array_like + Value(s) to write on the diagonal. If `val` is scalar, the value is + written along the diagonal. If array-like, the flattened `val` is + written along the diagonal, repeating if necessary to fill all + diagonal entries. wrap : bool For tall matrices in NumPy version up to 1.6.2, the -- cgit v1.2.1 From 92170a83e24b0a4468007ea4507e3a0ba0c30cd7 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Thu, 3 Sep 2020 12:12:50 +0100 Subject: DEP: Deprecated ndindex.ndincr The "do not use" comment has been here since bb0e4f356cce2f199d9c08ffe572fbabadc846d1. --- numpy/lib/index_tricks.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'numpy/lib/index_tricks.py') diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py index 6093f7e9d..9d3de69dd 100644 --- a/numpy/lib/index_tricks.py +++ b/numpy/lib/index_tricks.py @@ -1,6 +1,7 @@ import functools import sys import math +import warnings import numpy.core.numeric as _nx from numpy.core.numeric import ( @@ -659,7 +660,15 @@ class ndindex: Increment the multi-dimensional index by one. This method is for backward compatibility only: do not use. + + .. deprecated:: 1.20.0 + This method has been advised against since numpy 1.8.0, but only + started emitting DeprecationWarning as of this version. """ + # NumPy 1.20.0, 2020-09-08 + warnings.warn( + "`ndindex.ndincr()` is deprecated, use `next(ndindex)` instead", + DeprecationWarning, stacklevel=2) next(self) def __next__(self): -- cgit v1.2.1