Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit13b5692

Browse files
committed
Apply review comments
1 parent0892ed3 commit13b5692

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 lasttwo axes only) should be used instead."
859859
"(Deprecated NumPy 2.3)",ndim)<0) {
860860
returnNULL;
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 youcall `.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 youcalled `.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
importnumpyasnp
1414
fromnumpy.testingimportassert_raises,temppath
1515

16-
try:
17-
importpytz# noqa: F401
18-
_has_pytz=True
19-
exceptImportError:
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
defteardown_method(self):
4438
self.warn_ctx.__exit__()
4539

46-
defassert_deprecated(self,function,num=1,msg_patterns=None,
47-
ignore_others=False,
40+
defassert_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
forwarninginself.log:
103-
ifmsg_patternsisnotNone:
104-
pattern= (msg_patternsifisinstance(msg_patterns,str)else
105-
msg_patterns[num_found])
106-
msg=warning.message.args[0]
107-
ifre.match(pattern,msg)isNone:
108-
raiseAssertionError(
109-
"expected %s warning message pattern but got: %s"%
110-
(pattern,msg))
11191
ifwarning.categoryisself.warning_cls:
11292
num_found+=1
11393
elifnotignore_others:
@@ -157,17 +137,9 @@ def test_assert_deprecated(self):
157137
lambda:None)
158138

159139
deffoo():
160-
warnings.warn("foo bar",category=DeprecationWarning,
161-
stacklevel=2)
162-
163-
deffoo_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-
classTestDeprecatedTNon2Dim(_DeprecationTestCase):
480-
# Deprecated in Numpy 2.3, 2025-04
451+
classTestDeprecatedTPropScalar(_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+
deftest_deprecated(self):
457+
self.assert_deprecated(lambda:np.int64(1).T)
458+
459+
460+
classTestDeprecatedTPropNon2Dim(_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
deftest_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
forshapein [(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)

[8]ページ先頭

©2009-2025 Movatter.jp