10000 adjust tests · numpy/numpy@f9a2e00 · GitHub
[go: up one dir, main page]

Skip to content

Commit f9a2e00

Browse files
committed
adjust tests
1 parent c27f61a commit f9a2e00

File tree

7 files changed

+34
-13
lines changed

7 files changed

+34
-13
lines changed

numpy/_core/tests/test_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy._core.umath as ncu
55
from numpy._core._rational_tests import rational
66
import pytest
7+
from numpy.lib import stride_tricks
78
from numpy.testing import (
89
assert_, assert_equal, assert_array_equal, assert_raises, assert_warns,
910
HAS_REFCOUNT
@@ -553,7 +554,7 @@ def check_copy_result(x, y, ccontig, fcontig, strides=False):
553554

554555
def test_contiguous_flags():
555556
a = np.ones((4, 4, 1))[::2, :, :]
556-
a.strides = a.strides[:2] + (-123,)
557+
a = stride_tricks.as_strided(a, strides = a.strides[:2] + (-123,))
557558
b = np.ones((2, 2, 1, 2, 2)).swapaxes(3, 4)
558559

559560
def check_contig(a, ccontig, fcontig):

numpy/_core/tests/test_half.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TestHalf:
2020
def setup_method(self):
2121
# An array of all possible float16 values
2222
self.all_f16 = np.arange(0x10000, dtype=uint16)
23-
self.all_f16.dtype = float16
23+
self.all_f16 = self.all_f16.view(float16)
2424

2525
# NaN value can cause an invalid FP exception if HW is being used
2626
with np.errstate(invalid='ignore'):
@@ -31,7 +31,7 @@ def setup_method(self):
3131
self.nonan_f16 = np.concatenate(
3232
(np.arange(0xfc00, 0x7fff, -1, dtype=uint16),
3333
np.arange(0x0000, 0x7c01, 1, dtype=uint16)))
34-
self.nonan_f16.dtype = float16
34+
self.nonan_f16 = self.nonan_f16.view(float16)
3535
self.nonan_f32 = np.array(self.nonan_f16, dtype=float32)
3636
self.nonan_f64 = np.array(self.nonan_f16, dtype=float64)
3737

@@ -217,7 +217,7 @@ def test_half_values(self):
217217
0x0001, 0x8001,
218218
0x0000, 0x8000,
219219
0x7c00, 0xfc00], dtype=uint16)
220-
b.dtype = float16
220+
b = b.view(dtype = float16)
221221
assert_equal(a, b)
222222

223223
def test_half_rounding(self):

numpy/_core/tests/test_multiarray.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from numpy._core.tests._locales import CommaDecimalPointLocale
3737
from numpy.lib.recfunctions import repack_fields
3838
from numpy._core.multiarray import _get_ndarray_c_version, dot
39+
from numpy.lib import stride_tricks
3940

4041
# Need to test an object that does not fully implement math interface
4142
from datetime import timedelta, datetime
@@ -358,6 +359,7 @@ def make_array(size, offset, strides):
358359
make_array(0, 0, 10)
359360

360361
def test_set_stridesattr(self):
362+
# gh-28901: setting strides has been deprecated
361363
x = self.one
362364

363365
def make_array(size, offset, strides):
@@ -3636,7 +3638,9 @@ def test_ravel(self):
36363638

36373639
# 1-element tidy strides test:
36383640
a = np.array([[1]])
3639-
a.strides = (123, 432)
3641+
with warnings.catch_warnings(): # gh-28901
3642+
warnings.filterwarnings("ignore", category=DeprecationWarning)
3643+
a.strides = (123, 432)
36403644
if np.ones(1).strides == (8,):
36413645
assert_(np.may_share_memory(a.ravel('K'), a))
36423646
assert_equal(a.ravel('K').strides, (a.dtype.itemsize,))

numpy/_core/tests/test_regression.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,18 +427,24 @@ def test_lexsort_zerolen_custom_strides(self):
427427
xs = np.array([], dtype='i8')
428428
assert np.lexsort((xs,)).shape[0] == 0 # Works
429429

430-
xs.strides = (16,)
430+
with warnings.catch_warnings(): # gh-28901
431+
warnings.filterwarnings("ignore", category=DeprecationWarning)
432+
xs.strides = (16,)
431433
assert np.lexsort((xs,)).shape[0] == 0 # Was: MemoryError
432434

433435
def test_lexsort_zerolen_custom_strides_2d(self):
434436
xs = np.array([], dtype='i8')
435437

436438
xs.shape = (0, 2)
437-
xs.strides = (16, 16)
439+
with warnings.catch_warnings(): # gh-28901
440+
warnings.filterwarnings("ignore", category=DeprecationWarning)
441+
xs.strides = (16, 16)
438442
assert np.lexsort((xs,), axis=0).shape[0] == 0
439443

440444
xs.shape = (2, 0)
441-
xs.strides = (16, 16)
445+
with warnings.catch_warnings(): # gh-28901
446+
warnings.filterwarnings("ignore", category=DeprecationWarning)
447+
xs.strides = (16, 16)
442448
assert np.lexsort((xs,), axis=0).shape[0] == 2
443449

444450
def test_lexsort_invalid_axis(self):
@@ -1870,7 +1876,9 @@ def test_alignment_update(self):
18701876
# Check that alignment flag is updated on stride setting
18711877
a = np.arange(10)
18721878
assert_(a.flags.aligned)
1873-
a.strides = 3
1879+
with warnings.catch_warnings(): # gh-28901
1880+
warnings.filterwarnings("ignore", category=DeprecationWarning)
1881+
a.strides = 3
18741882
assert_(not a.flags.aligned)
18751883

18761884
def test_ticket_1770(self):

numpy/lib/_npyio_impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ def fromregex(file, regexp, dtype, encoding=None):
17291729
# re-interpret as a single-field structured array.
17301730
newdtype = np.dtype(dtype[dtype.names[0]])
17311731
output = np.array(seq, dtype=newdtype)
1732-
output.dtype = dtype
1732+
output = output.view(dtype)
17331733
else:
17341734
output = np.array(seq, dtype=dtype)
17351735

numpy/ma/tests/test_core.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,11 @@ def test_assign_dtype(self):
21262126
a = np.zeros(4, dtype='f4,i4')
21272127

21282128
m = np.ma.array(a)
2129-
m.dtype = np.dtype('f4')
2129+
with warnings.catch_warnings():
2130+
# gh-28901
2131+
warnings.filterwarnings("ignore", category=DeprecationWarning)
2132+
2133+
m.dtype = np.dtype('f4')
21302134
repr(m) # raises?
21312135
assert_equal(m.dtype, np.dtype('f4'))
21322136

@@ -2143,7 +2147,11 @@ def assign():
21432147
# check that nomask is preserved
21442148
a = np.zeros(4, dtype='f4')
21452149
m = np.ma.array(a)
2146-
m.dtype = np.dtype('f4,i4')
2150+
with warnings.catch_warnings():
2151+
# gh-28901
2152+
warnings.filterwarnings("ignore", category=DeprecationWarning)
2153+
2154+
m.dtype = np.dtype('f4,i4')
21472155
assert_equal(m.dtype, np.dtype('f4,i4'))
21482156
assert_equal(m._mask, np.ma.nomask)
21492157

numpy/typing/__init__.py

Lin 878 es changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
ndarray
6565
~~~~~~~
6666

67-
It's possible to mutate the dtype of an array at runtime. For example,
67+
It's possible (but deprecated) to mutate the dtype of an array at runtime. For example,
6868
the following code is valid:
6969

7070
.. code-block:: python

0 commit comments

Comments
 (0)
0