Skip to content

Commit cb4e11f

Browse files
nimrod-gileadicopybara-github
authored andcommitted
Fix a couple of tests that break under numpy>=2.0.
Some attributes of np.ndarray were deprecated and shouldn't be accessed. PiperOrigin-RevId: 665798008 Change-Id: I80e965ca39cb4c8fb1eb8362cdd665b34755dcd9
1 parent c710837 commit cb4e11f

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

dm_control/mujoco/index_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
'4 mocap2 [ 12 13 14 ]'),
5353
}
5454

55+
# A test below accesses all attributes of np.ndarray, but accessing some of them
56+
# triggers an exception under numpy>=2.0.
57+
_DEPRECATED_NDARRAY_ATTRIBUTES = {
58+
'itemset', 'newbyteorder', 'ptp'
59+
}
60+
5561

5662
class MujocoIndexTest(parameterized.TestCase):
5763

@@ -291,6 +297,7 @@ def testBuildIndexersForEdgeCases(self, xml_string):
291297
(name, name) for name in dir(np.ndarray)
292298
if not name.startswith('_') # Exclude 'private' attributes
293299
and name not in ('ctypes', 'flat') # Can't compare via identity/equality
300+
and name not in _DEPRECATED_NDARRAY_ATTRIBUTES
294301
])
295302
# pylint: enable=undefined-variable
296303
def testFieldIndexerDelegatesNDArrayAttributes(self, name):

dm_control/utils/inverse_kinematics_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def testQposFromSitePose(self, target, inplace):
118118
xmat = physics.named.data.site_xmat[_SITE_NAME]
119119
quat = np.empty_like(target_quat)
120120
mjlib.mju_mat2Quat(quat, xmat)
121-
quat /= quat.ptp() # Normalize xquat so that its max-min range is 1
121+
quat /= np.ptp(quat) # Normalize xquat so that its max-min range is 1
122122
np.testing.assert_array_almost_equal(quat, target_quat)
123123

124124
def testNamedJointsWithMultipleDOFs(self):

0 commit comments

Comments
 (0)