Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e411971

Browse filesBrowse files
committed
Apply review comments
1 parent cc623f9 commit e411971
Copy full SHA for e411971

File tree

Expand file treeCollapse file tree

4 files changed

+25
-54
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+25
-54
lines changed

‎doc/release/upcoming_changes/28678.deprecation.rst

Copy file name to clipboardExpand all lines: doc/release/upcoming_changes/28678.deprecation.rst
+1-1Lines 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

Copy file name to clipboardExpand all lines: numpy/_core/src/multiarray/getset.c
+4-4Lines 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

Copy file name to clipboardExpand all lines: numpy/_core/src/multiarray/scalartypes.c.src
+3-3Lines 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

Copy file name to clipboardExpand all lines: numpy/_core/tests/test_deprecations.py
+17-46Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,10 @@
77
import pytest
88

99
import numpy as np
10-
from numpy.testing import (
11-
assert_raises, temppath
12-
)
10+
from numpy.testing import assert_raises, temppath
1311

14-
from numpy._core._multiarray_tests import fromstring_null_term_c_api # noqa: F401
1512
import numpy._core._struct_ufunc_tests as struct_ufunc
1613

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

2415
class _DeprecationTestCase:
2516
# Just as warning: warnings uses re.match, so the start of this message
@@ -44,8 +35,7 @@ def setup_method(self):
4435
def teardown_method(self):
4536
self.warn_ctx.__exit__()
4637

47-
def assert_deprecated(self, function, num=1, msg_patterns=None,
48-
ignore_others=False,
38+
def assert_deprecated(self, function, num=1, ignore_others=False,
4939
function_fails=False,
5040
exceptions=np._NoValue,
5141
args=(), kwargs={}):
@@ -63,11 +53,6 @@ def assert_deprecated(self, function, num=1, msg_patterns=None,
6353
The function to test
6454
num : int
6555
Number of DeprecationWarnings to expect. This should normally be 1.
66-
msg_patterns : str or tuple of str
67-
Patterns for which warning messages should match. For `str` each
68-
warning should match to the same pattern. For a tuple of `str`
69-
each warning should match against the corresponding pattern.
70-
For `None` this check is skipped.
7156
ignore_others : bool
7257
Whether warnings of the wrong type should be ignored (note that
7358
the message is not checked)
@@ -99,14 +84,6 @@ def assert_deprecated(self, function, num=1, msg_patterns=None,
9984
# just in case, clear the registry
10085
num_found = 0
10186
for warning in self.log:
102-
if msg_patterns is not None:
103-
pattern = (msg_patterns if isinstance(msg_patterns, str) else
104-
msg_patterns[num_found])
105-
msg = warning.message.args[0]
106-
if re.match(pattern, msg) is None:
107-
raise AssertionError(
108-
"expected %s warning message pattern but got: %s" %
109-
(pattern, msg))
11087
if warning.category is self.warning_cls:
11188
num_found += 1
11289
elif not ignore_others:
@@ -156,17 +133,9 @@ def test_assert_deprecated(self):
156133
lambda: None)
157134

158135
def foo():
159-
warnings.warn("foo bar", category=DeprecationWarning,
160-
stacklevel=2)
161-
162-
def foo_many():
163136
warnings.warn("foo", category=DeprecationWarning, stacklevel=2)
164-
warnings.warn("bar", category=DeprecationWarning, stacklevel=2)
165137

166138
test_case_instance.assert_deprecated(foo)
167-
test_case_instance.assert_deprecated(foo, msg_patterns="foo")
168-
test_case_instance.assert_deprecated(foo_many, num=2,
169-
msg_patterns=("foo", "^bar$"))
170139
test_case_instance.teardown_method()
171140

172141

@@ -475,18 +444,20 @@ def test_deprecated(self):
475444
)
476445

477446

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.