Content-Length: 531211 | pFad | http://github.com/numpy/numpy/commit/13b5692a2df80fe8e7568340b07d2bc58c87fc45

3C Apply review comments · numpy/numpy@13b5692 · GitHub
Skip to content

Commit 13b5692

Browse files
committed
Apply review comments
1 parent 0892ed3 commit 13b5692

File tree

4 files changed

+24
-50
lines changed

4 files changed

+24
-50
lines changed

doc/release/upcoming_changes/28678.deprecation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
* ``arr.T`` property has been deprecated for array scalars and arrays with dimensionality
1+
* The ``arr.T`` property has been deprecated for array scalars and arrays with dimensionality
22
different than ``2`` to be compatible with the Array API standard. To achieve similar
33
behavior when ``arr.ndim != 2``, either ``arr.transpose()``, or ``arr.mT`` (swaps
44
the last two axes only), or ``np.permute_dims(arr, range(arr.ndim)[::-1])`` (compatible

numpy/_core/src/multiarray/getset.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -852,10 +852,10 @@ array_transpose_get(PyArrayObject *self, void *NPY_UNUSED(ignored))
852852
if (ndim != 2) {
853853
/* Deprecated 2025-04-19, NumPy 2.3 */
854854
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
855-
"In the future `.T` property will be supported for "
856-
"2-dim arrays only. Received %d-dim array. Either "
857-
"`arr.transpose()` or `.mT` (which swaps the last "
858-
"two axes only) should be used instead."
855+
"In the future, the `.T` property will be supported for "
856+
"2-dimensional arrays only. Received %d-dimensional "
857+
"array. Either `arr.transpose()` or `.mT` (which swaps "
858+
"the last two axes only) should be used instead."
859859
"(Deprecated NumPy 2.3)", ndim) < 0) {
860860
return NULL;
861861
}

numpy/_core/src/multiarray/scalartypes.c.src

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,9 +1927,9 @@ gentype_transpose_get(PyObject *self, void *NPY_UNUSED(ignored))
19271927
{
19281928
/* Deprecated 2025-04-19, NumPy 2.3 */
19291929
if (DEPRECATE(
1930-
"In the future `.T` property for array scalars will "
1931-
"raise an error. If you call `.T` on an array scalar "
1932-
"intentionally you can safely drop it. In other cases "
1930+
"In the future, the `.T` property for array scalars will "
1931+
"raise an error. If you called `.T` on an array scalar "
1932+
"intentionally, you can safely drop it. In other cases, "
19331933
"`arr.transpose()` or `.mT` (which swaps the last "
19341934
"two axes only) should be used instead. "
19351935
"(Deprecated NumPy 2.3)") < 0) {

numpy/_core/tests/test_deprecations.py

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
import numpy as np
1414
from numpy.testing import assert_raises, temppath
1515

16-
try:
17-
import pytz # noqa: F401
18-
_has_pytz = True
19-
except ImportError:
20-
_has_pytz = False
21-
2216

2317
class _DeprecationTestCase:
2418
# Just as warning: warnings uses re.match, so the start of this message
@@ -43,8 +37,7 @@ def setup_method(self):
4337
def teardown_method(self):
4438
self.warn_ctx.__exit__()
4539

46-
def assert_deprecated(self, function, num=1, msg_patterns=None,
47-
ignore_others=False,
40+
def assert_deprecated(self, function, num=1, ignore_others=False,
4841
function_fails=False,
4942
exceptions=np._NoValue,
5043
args=(), kwargs={}):
@@ -62,11 +55,6 @@ def assert_deprecated(self, function, num=1, msg_patterns=None,
6255
The function to test
6356
num : int
6457
Number of DeprecationWarnings to expect. This should normally be 1.
65-
msg_patterns : str or tuple of str
66-
Patterns for which warning messages should match. For `str` each
67-
warning should match to the same pattern. For a tuple of `str`
68-
each warning should match against the corresponding pattern.
69-
For `None` this check is skipped.
7058
ignore_others : bool
7159
Whether warnings of the wrong type should be ignored (note that
7260
the message is not checked)
@@ -100,14 +88,6 @@ def assert_deprecated(self, function, num=1, msg_patterns=None,
10088
# just in case, clear the registry
10189
num_found = 0
10290
for warning in self.log:
103-
if msg_patterns is not None:
104-
pattern = (msg_patterns if isinstance(msg_patterns, str) else
105-
msg_patterns[num_found])
106-
msg = warning.message.args[0]
107-
if re.match(pattern, msg) is None:
108-
raise AssertionError(
109-
"expected %s warning message pattern but got: %s" %
110-
(pattern, msg))
11191
if warning.category is self.warning_cls:
11292
num_found += 1
11393
elif not ignore_others:
@@ -157,17 +137,9 @@ def test_assert_deprecated(self):
157137
lambda: None)
158138

159139
def foo():
160-
warnings.warn("foo bar", category=DeprecationWarning,
161-
stacklevel=2)
162-
163-
def foo_many():
164140
warnings.warn("foo", category=DeprecationWarning, stacklevel=2)
165-
warnings.warn("bar", category=DeprecationWarning, stacklevel=2)
166141

167142
test_case_instance.assert_deprecated(foo)
168-
test_case_instance.assert_deprecated(foo, msg_patterns="foo")
169-
test_case_instance.assert_deprecated(foo_many, num=2,
170-
msg_patterns=("foo", "^bar$"))
171143
test_case_instance.teardown_method()
172144

173145

@@ -476,18 +448,20 @@ def test_deprecated(self):
476448
)
477449

478450

479-
class TestDeprecatedTNon2Dim(_DeprecationTestCase):
480-
# Deprecated in Numpy 2.3, 2025-04
451+
class TestDeprecatedTPropScalar(_DeprecationTestCase):
452+
# Deprecated in Numpy 2.3, 2025-05
453+
message = ("In the future, the `.T` property for array scalars will "
454+
"raise an error.")
455+
456+
def test_deprecated(self):
457+
self.assert_deprecated(lambda: np.int64(1).T)
458+
459+
460+
class TestDeprecatedTPropNon2Dim(_DeprecationTestCase):
461+
# Deprecated in Numpy 2.3, 2025-05
462+
message = ("In the future, the `.T` property will be supported for "
463+
r"2-dimensional arrays only. Received \d+-dimensional array.")
464+
481465
def test_deprecated(self):
482-
self.assert_deprecated(
483-
lambda: np.int64(1).T,
484-
msg_patterns="In the future `.T` property for "
485-
"array scalars will raise an error."
486-
)
487466
for shape in [(5,), (2, 3, 4)]:
488-
self.assert_deprecated(
489-
lambda: np.ones(shape).T,
490-
msg_patterns="In the future `.T` property will be "
491-
"supported for 2-dim arrays only. "
492-
f"Received {len(shape)}-dim array."
493-
)
467+
self.assert_deprecated(lambda: np.ones(shape).T)

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/numpy/numpy/commit/13b5692a2df80fe8e7568340b07d2bc58c87fc45

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy