PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/monitor_batch/pymodules/python2.7/lib/python/numpy/core/tests/test_deprecations.py

https://gitlab.com/pooja043/Globus_Docker_4
Python | 635 lines | 522 code | 42 blank | 71 comment | 14 complexity | 3ac93c3477203f47cc309c5fdf9dfc7f MD5 | raw file
  1. """
  2. Tests related to deprecation warnings. Also a convenient place
  3. to document how deprecations should eventually be turned into errors.
  4. """
  5. from __future__ import division, absolute_import, print_function
  6. import sys
  7. import operator
  8. import warnings
  9. import numpy as np
  10. from numpy.testing import (
  11. run_module_suite, assert_raises, assert_warns, assert_no_warnings,
  12. assert_array_equal, assert_)
  13. class _DeprecationTestCase(object):
  14. # Just as warning: warnings uses re.match, so the start of this message
  15. # must match.
  16. message = ''
  17. def setUp(self):
  18. self.warn_ctx = warnings.catch_warnings(record=True)
  19. self.log = self.warn_ctx.__enter__()
  20. # Do *not* ignore other DeprecationWarnings. Ignoring warnings
  21. # can give very confusing results because of
  22. # http://bugs.python.org/issue4180 and it is probably simplest to
  23. # try to keep the tests cleanly giving only the right warning type.
  24. # (While checking them set to "error" those are ignored anyway)
  25. # We still have them show up, because otherwise they would be raised
  26. warnings.filterwarnings("always", category=DeprecationWarning)
  27. warnings.filterwarnings("always", message=self.message,
  28. category=DeprecationWarning)
  29. def tearDown(self):
  30. self.warn_ctx.__exit__()
  31. def assert_deprecated(self, function, num=1, ignore_others=False,
  32. function_fails=False,
  33. exceptions=(DeprecationWarning,), args=(), kwargs={}):
  34. """Test if DeprecationWarnings are given and raised.
  35. This first checks if the function when called gives `num`
  36. DeprecationWarnings, after that it tries to raise these
  37. DeprecationWarnings and compares them with `exceptions`.
  38. The exceptions can be different for cases where this code path
  39. is simply not anticipated and the exception is replaced.
  40. Parameters
  41. ----------
  42. f : callable
  43. The function to test
  44. num : int
  45. Number of DeprecationWarnings to expect. This should normally be 1.
  46. ignore_other : bool
  47. Whether warnings of the wrong type should be ignored (note that
  48. the message is not checked)
  49. function_fails : bool
  50. If the function would normally fail, setting this will check for
  51. warnings inside a try/except block.
  52. exceptions : Exception or tuple of Exceptions
  53. Exception to expect when turning the warnings into an error.
  54. The default checks for DeprecationWarnings. If exceptions is
  55. empty the function is expected to run successfull.
  56. args : tuple
  57. Arguments for `f`
  58. kwargs : dict
  59. Keyword arguments for `f`
  60. """
  61. # reset the log
  62. self.log[:] = []
  63. try:
  64. function(*args, **kwargs)
  65. except (Exception if function_fails else tuple()):
  66. pass
  67. # just in case, clear the registry
  68. num_found = 0
  69. for warning in self.log:
  70. if warning.category is DeprecationWarning:
  71. num_found += 1
  72. elif not ignore_others:
  73. raise AssertionError(
  74. "expected DeprecationWarning but got: %s" %
  75. (warning.category,))
  76. if num is not None and num_found != num:
  77. msg = "%i warnings found but %i expected." % (len(self.log), num)
  78. lst = [w.category for w in self.log]
  79. raise AssertionError("\n".join([msg] + [lst]))
  80. with warnings.catch_warnings():
  81. warnings.filterwarnings("error", message=self.message,
  82. category=DeprecationWarning)
  83. try:
  84. function(*args, **kwargs)
  85. if exceptions != tuple():
  86. raise AssertionError(
  87. "No error raised during function call")
  88. except exceptions:
  89. if exceptions == tuple():
  90. raise AssertionError(
  91. "Error raised during function call")
  92. def assert_not_deprecated(self, function, args=(), kwargs={}):
  93. """Test if DeprecationWarnings are given and raised.
  94. This is just a shorthand for:
  95. self.assert_deprecated(function, num=0, ignore_others=True,
  96. exceptions=tuple(), args=args, kwargs=kwargs)
  97. """
  98. self.assert_deprecated(function, num=0, ignore_others=True,
  99. exceptions=tuple(), args=args, kwargs=kwargs)
  100. class TestFloatNonIntegerArgumentDeprecation(_DeprecationTestCase):
  101. """
  102. These test that ``DeprecationWarning`` is given when you try to use
  103. non-integers as arguments to for indexing and slicing e.g. ``a[0.0:5]``
  104. and ``a[0.5]``, or other functions like ``array.reshape(1., -1)``.
  105. After deprecation, changes need to be done inside conversion_utils.c
  106. in PyArray_PyIntAsIntp and possibly PyArray_IntpConverter.
  107. In iterators.c the function slice_GetIndices could be removed in favor
  108. of its python equivalent and in mapping.c the function _tuple_of_integers
  109. can be simplified (if ``np.array([1]).__index__()`` is also deprecated).
  110. As for the deprecation time-frame: via Ralf Gommers,
  111. "Hard to put that as a version number, since we don't know if the
  112. version after 1.8 will be 6 months or 2 years after. I'd say 2
  113. years is reasonable."
  114. I interpret this to mean 2 years after the 1.8 release. Possibly
  115. giving a PendingDeprecationWarning before that (which is visible
  116. by default)
  117. """
  118. message = "using a non-integer number instead of an integer " \
  119. "will result in an error in the future"
  120. def test_indexing(self):
  121. a = np.array([[[5]]])
  122. def assert_deprecated(*args, **kwargs):
  123. self.assert_deprecated(*args, exceptions=(IndexError,), **kwargs)
  124. assert_deprecated(lambda: a[0.0])
  125. assert_deprecated(lambda: a[0, 0.0])
  126. assert_deprecated(lambda: a[0.0, 0])
  127. assert_deprecated(lambda: a[0.0,:])
  128. assert_deprecated(lambda: a[:, 0.0])
  129. assert_deprecated(lambda: a[:, 0.0,:])
  130. assert_deprecated(lambda: a[0.0,:,:])
  131. assert_deprecated(lambda: a[0, 0, 0.0])
  132. assert_deprecated(lambda: a[0.0, 0, 0])
  133. assert_deprecated(lambda: a[0, 0.0, 0])
  134. assert_deprecated(lambda: a[-1.4])
  135. assert_deprecated(lambda: a[0, -1.4])
  136. assert_deprecated(lambda: a[-1.4, 0])
  137. assert_deprecated(lambda: a[-1.4,:])
  138. assert_deprecated(lambda: a[:, -1.4])
  139. assert_deprecated(lambda: a[:, -1.4,:])
  140. assert_deprecated(lambda: a[-1.4,:,:])
  141. assert_deprecated(lambda: a[0, 0, -1.4])
  142. assert_deprecated(lambda: a[-1.4, 0, 0])
  143. assert_deprecated(lambda: a[0, -1.4, 0])
  144. # Test that the slice parameter deprecation warning doesn't mask
  145. # the scalar index warning.
  146. assert_deprecated(lambda: a[0.0:, 0.0], num=2)
  147. assert_deprecated(lambda: a[0.0:, 0.0,:], num=2)
  148. def test_valid_indexing(self):
  149. a = np.array([[[5]]])
  150. assert_not_deprecated = self.assert_not_deprecated
  151. assert_not_deprecated(lambda: a[np.array([0])])
  152. assert_not_deprecated(lambda: a[[0, 0]])
  153. assert_not_deprecated(lambda: a[:, [0, 0]])
  154. assert_not_deprecated(lambda: a[:, 0,:])
  155. assert_not_deprecated(lambda: a[:,:,:])
  156. def test_slicing(self):
  157. a = np.array([[5]])
  158. def assert_deprecated(*args, **kwargs):
  159. self.assert_deprecated(*args, exceptions=(IndexError,), **kwargs)
  160. # start as float.
  161. assert_deprecated(lambda: a[0.0:])
  162. assert_deprecated(lambda: a[0:, 0.0:2])
  163. assert_deprecated(lambda: a[0.0::2, :0])
  164. assert_deprecated(lambda: a[0.0:1:2,:])
  165. assert_deprecated(lambda: a[:, 0.0:])
  166. # stop as float.
  167. assert_deprecated(lambda: a[:0.0])
  168. assert_deprecated(lambda: a[:0, 1:2.0])
  169. assert_deprecated(lambda: a[:0.0:2, :0])
  170. assert_deprecated(lambda: a[:0.0,:])
  171. assert_deprecated(lambda: a[:, 0:4.0:2])
  172. # step as float.
  173. assert_deprecated(lambda: a[::1.0])
  174. assert_deprecated(lambda: a[0:, :2:2.0])
  175. assert_deprecated(lambda: a[1::4.0, :0])
  176. assert_deprecated(lambda: a[::5.0,:])
  177. assert_deprecated(lambda: a[:, 0:4:2.0])
  178. # mixed.
  179. assert_deprecated(lambda: a[1.0:2:2.0], num=2)
  180. assert_deprecated(lambda: a[1.0::2.0], num=2)
  181. assert_deprecated(lambda: a[0:, :2.0:2.0], num=2)
  182. assert_deprecated(lambda: a[1.0:1:4.0, :0], num=2)
  183. assert_deprecated(lambda: a[1.0:5.0:5.0,:], num=3)
  184. assert_deprecated(lambda: a[:, 0.4:4.0:2.0], num=3)
  185. # should still get the DeprecationWarning if step = 0.
  186. assert_deprecated(lambda: a[::0.0], function_fails=True)
  187. def test_valid_slicing(self):
  188. a = np.array([[[5]]])
  189. assert_not_deprecated = self.assert_not_deprecated
  190. assert_not_deprecated(lambda: a[::])
  191. assert_not_deprecated(lambda: a[0:])
  192. assert_not_deprecated(lambda: a[:2])
  193. assert_not_deprecated(lambda: a[0:2])
  194. assert_not_deprecated(lambda: a[::2])
  195. assert_not_deprecated(lambda: a[1::2])
  196. assert_not_deprecated(lambda: a[:2:2])
  197. assert_not_deprecated(lambda: a[1:2:2])
  198. def test_non_integer_argument_deprecations(self):
  199. a = np.array([[5]])
  200. self.assert_deprecated(np.reshape, args=(a, (1., 1., -1)), num=2)
  201. self.assert_deprecated(np.reshape, args=(a, (np.array(1.), -1)))
  202. self.assert_deprecated(np.take, args=(a, [0], 1.))
  203. self.assert_deprecated(np.take, args=(a, [0], np.float64(1.)))
  204. def test_non_integer_sequence_multiplication(self):
  205. # Numpy scalar sequence multiply should not work with non-integers
  206. def mult(a, b):
  207. return a * b
  208. self.assert_deprecated(mult, args=([1], np.float_(3)))
  209. self.assert_not_deprecated(mult, args=([1], np.int_(3)))
  210. def test_reduce_axis_float_index(self):
  211. d = np.zeros((3,3,3))
  212. self.assert_deprecated(np.min, args=(d, 0.5))
  213. self.assert_deprecated(np.min, num=1, args=(d, (0.5, 1)))
  214. self.assert_deprecated(np.min, num=1, args=(d, (1, 2.2)))
  215. self.assert_deprecated(np.min, num=2, args=(d, (.2, 1.2)))
  216. class TestBooleanArgumentDeprecation(_DeprecationTestCase):
  217. """This tests that using a boolean as integer argument/indexing is
  218. deprecated.
  219. This should be kept in sync with TestFloatNonIntegerArgumentDeprecation
  220. and like it is handled in PyArray_PyIntAsIntp.
  221. """
  222. message = "using a boolean instead of an integer " \
  223. "will result in an error in the future"
  224. def test_bool_as_int_argument(self):
  225. a = np.array([[[1]]])
  226. self.assert_deprecated(np.reshape, args=(a, (True, -1)))
  227. self.assert_deprecated(np.reshape, args=(a, (np.bool_(True), -1)))
  228. # Note that operator.index(np.array(True)) does not work, a boolean
  229. # array is thus also deprecated, but not with the same message:
  230. assert_raises(TypeError, operator.index, np.array(True))
  231. self.assert_deprecated(np.take, args=(a, [0], False))
  232. self.assert_deprecated(lambda: a[False:True:True], exceptions=IndexError, num=3)
  233. self.assert_deprecated(lambda: a[False, 0], exceptions=IndexError)
  234. self.assert_deprecated(lambda: a[False, 0, 0], exceptions=IndexError)
  235. class TestArrayToIndexDeprecation(_DeprecationTestCase):
  236. """This tests that creating an an index from an array is deprecated
  237. if the array is not 0d.
  238. This can probably be deprecated somewhat faster then the integer
  239. deprecations. The deprecation period started with NumPy 1.8.
  240. For deprecation this needs changing of array_index in number.c
  241. """
  242. message = "converting an array with ndim \> 0 to an index will result " \
  243. "in an error in the future"
  244. def test_array_to_index_deprecation(self):
  245. # This drops into the non-integer deprecation, which is ignored here,
  246. # so no exception is expected. The raising is effectively tested above.
  247. a = np.array([[[1]]])
  248. self.assert_deprecated(operator.index, args=(np.array([1]),))
  249. self.assert_deprecated(np.reshape, args=(a, (a, -1)), exceptions=())
  250. self.assert_deprecated(np.take, args=(a, [0], a), exceptions=())
  251. # Check slicing. Normal indexing checks arrays specifically.
  252. self.assert_deprecated(lambda: a[a:a:a], exceptions=(), num=3)
  253. class TestNonIntegerArrayLike(_DeprecationTestCase):
  254. """Tests that array likes, i.e. lists give a deprecation warning
  255. when they cannot be safely cast to an integer.
  256. """
  257. message = "non integer \(and non boolean\) array-likes will not be " \
  258. "accepted as indices in the future"
  259. def test_basic(self):
  260. a = np.arange(10)
  261. self.assert_deprecated(a.__getitem__, args=([0.5, 1.5],),
  262. exceptions=IndexError)
  263. self.assert_deprecated(a.__getitem__, args=((['1', '2'],),),
  264. exceptions=IndexError)
  265. self.assert_not_deprecated(a.__getitem__, ([],))
  266. def test_boolean_futurewarning(self):
  267. a = np.arange(10)
  268. with warnings.catch_warnings():
  269. warnings.filterwarnings('always')
  270. assert_warns(FutureWarning, a.__getitem__, [True])
  271. # Unfortunatly, the deprecation warning takes precedence:
  272. #assert_warns(FutureWarning, a.__getitem__, True)
  273. with warnings.catch_warnings():
  274. warnings.filterwarnings('error')
  275. assert_raises(FutureWarning, a.__getitem__, [True])
  276. #assert_raises(FutureWarning, a.__getitem__, True)
  277. class TestMultipleEllipsisDeprecation(_DeprecationTestCase):
  278. message = "an index can only have a single Ellipsis \(`...`\); replace " \
  279. "all but one with slices \(`:`\)."
  280. def test_basic(self):
  281. a = np.arange(10)
  282. self.assert_deprecated(a.__getitem__, args=((Ellipsis, Ellipsis),))
  283. with warnings.catch_warnings():
  284. warnings.filterwarnings('ignore', '', DeprecationWarning)
  285. # Just check that this works:
  286. b = a[...,...]
  287. assert_array_equal(a, b)
  288. assert_raises(IndexError, a.__getitem__, ((Ellipsis, ) * 3,))
  289. class TestBooleanUnaryMinusDeprecation(_DeprecationTestCase):
  290. """Test deprecation of unary boolean `-`. While + and * are well
  291. defined, unary - is not and even a corrected form seems to have
  292. no real uses.
  293. The deprecation process was started in NumPy 1.9.
  294. """
  295. message = r"numpy boolean negative, the `-` operator, .*"
  296. def test_unary_minus_operator_deprecation(self):
  297. array = np.array([True])
  298. generic = np.bool_(True)
  299. # Unary minus/negative ufunc:
  300. self.assert_deprecated(operator.neg, args=(array,))
  301. self.assert_deprecated(operator.neg, args=(generic,))
  302. class TestBooleanBinaryMinusDeprecation(_DeprecationTestCase):
  303. """Test deprecation of binary boolean `-`. While + and * are well
  304. defined, binary - is not and even a corrected form seems to have
  305. no real uses.
  306. The deprecation process was started in NumPy 1.9.
  307. """
  308. message = r"numpy boolean subtract, the `-` operator, .*"
  309. def test_operator_deprecation(self):
  310. array = np.array([True])
  311. generic = np.bool_(True)
  312. # Minus operator/subtract ufunc:
  313. self.assert_deprecated(operator.sub, args=(array, array))
  314. self.assert_deprecated(operator.sub, args=(generic, generic))
  315. class TestRankDeprecation(_DeprecationTestCase):
  316. """Test that np.rank is deprecated. The function should simply be
  317. removed. The VisibleDeprecationWarning may become unnecessary.
  318. """
  319. def test(self):
  320. a = np.arange(10)
  321. assert_warns(np.VisibleDeprecationWarning, np.rank, a)
  322. class TestComparisonDeprecations(_DeprecationTestCase):
  323. """This tests the deprecation, for non-elementwise comparison logic.
  324. This used to mean that when an error occured during element-wise comparison
  325. (i.e. broadcasting) NotImplemented was returned, but also in the comparison
  326. itself, False was given instead of the error.
  327. Also test FutureWarning for the None comparison.
  328. """
  329. message = "elementwise.* comparison failed; .*"
  330. def test_normal_types(self):
  331. for op in (operator.eq, operator.ne):
  332. # Broadcasting errors:
  333. self.assert_deprecated(op, args=(np.zeros(3), []))
  334. a = np.zeros(3, dtype='i,i')
  335. # (warning is issued a couple of times here)
  336. self.assert_deprecated(op, args=(a, a[:-1]), num=None)
  337. # Element comparison error (numpy array can't be compared).
  338. a = np.array([1, np.array([1,2,3])], dtype=object)
  339. b = np.array([1, np.array([1,2,3])], dtype=object)
  340. self.assert_deprecated(op, args=(a, b), num=None)
  341. def test_string(self):
  342. # For two string arrays, strings always raised the broadcasting error:
  343. a = np.array(['a', 'b'])
  344. b = np.array(['a', 'b', 'c'])
  345. assert_raises(ValueError, lambda x, y: x == y, a, b)
  346. # The empty list is not cast to string, this is only to document
  347. # that fact (it likely should be changed). This means that the
  348. # following works (and returns False) due to dtype mismatch:
  349. a == []
  350. def test_none_comparison(self):
  351. # Test comparison of None, which should result in elementwise
  352. # comparison in the future. [1, 2] == None should be [False, False].
  353. with warnings.catch_warnings():
  354. warnings.filterwarnings('always', '', FutureWarning)
  355. assert_warns(FutureWarning, operator.eq, np.arange(3), None)
  356. assert_warns(FutureWarning, operator.ne, np.arange(3), None)
  357. with warnings.catch_warnings():
  358. warnings.filterwarnings('error', '', FutureWarning)
  359. assert_raises(FutureWarning, operator.eq, np.arange(3), None)
  360. assert_raises(FutureWarning, operator.ne, np.arange(3), None)
  361. def test_scalar_none_comparison(self):
  362. # Scalars should still just return false and not give a warnings.
  363. # The comparisons are flagged by pep8, ignore that.
  364. with warnings.catch_warnings(record=True) as w:
  365. warnings.filterwarnings('always', '', FutureWarning)
  366. assert_(not np.float32(1) == None)
  367. assert_(not np.str_('test') == None)
  368. # This is dubious (see below):
  369. assert_(not np.datetime64('NaT') == None)
  370. assert_(np.float32(1) != None)
  371. assert_(np.str_('test') != None)
  372. # This is dubious (see below):
  373. assert_(np.datetime64('NaT') != None)
  374. assert_(len(w) == 0)
  375. # For documentaiton purpose, this is why the datetime is dubious.
  376. # At the time of deprecation this was no behaviour change, but
  377. # it has to be considered when the deprecations is done.
  378. assert_(np.equal(np.datetime64('NaT'), None))
  379. def test_void_dtype_equality_failures(self):
  380. class NotArray(object):
  381. def __array__(self):
  382. raise TypeError
  383. # Needed so Python 3 does not raise DeprecationWarning twice.
  384. def __ne__(self, other):
  385. return NotImplemented
  386. self.assert_deprecated(lambda: np.arange(2) == NotArray())
  387. self.assert_deprecated(lambda: np.arange(2) != NotArray())
  388. struct1 = np.zeros(2, dtype="i4,i4")
  389. struct2 = np.zeros(2, dtype="i4,i4,i4")
  390. assert_warns(FutureWarning, lambda: struct1 == 1)
  391. assert_warns(FutureWarning, lambda: struct1 == struct2)
  392. assert_warns(FutureWarning, lambda: struct1 != 1)
  393. assert_warns(FutureWarning, lambda: struct1 != struct2)
  394. def test_array_richcompare_legacy_weirdness(self):
  395. # It doesn't really work to use assert_deprecated here, b/c part of
  396. # the point of assert_deprecated is to check that when warnings are
  397. # set to "error" mode then the error is propagated -- which is good!
  398. # But here we are testing a bunch of code that is deprecated *because*
  399. # it has the habit of swallowing up errors and converting them into
  400. # different warnings. So assert_warns will have to be sufficient.
  401. assert_warns(FutureWarning, lambda: np.arange(2) == "a")
  402. assert_warns(FutureWarning, lambda: np.arange(2) != "a")
  403. # No warning for scalar comparisons
  404. with warnings.catch_warnings():
  405. warnings.filterwarnings("error")
  406. assert_(not (np.array(0) == "a"))
  407. assert_(np.array(0) != "a")
  408. assert_(not (np.int16(0) == "a"))
  409. assert_(np.int16(0) != "a")
  410. for arg1 in [np.asarray(0), np.int16(0)]:
  411. struct = np.zeros(2, dtype="i4,i4")
  412. for arg2 in [struct, "a"]:
  413. for f in [operator.lt, operator.le, operator.gt, operator.ge]:
  414. if sys.version_info[0] >= 3:
  415. # py3
  416. with warnings.catch_warnings() as l:
  417. warnings.filterwarnings("always")
  418. assert_raises(TypeError, f, arg1, arg2)
  419. assert not l
  420. else:
  421. # py2
  422. assert_warns(DeprecationWarning, f, arg1, arg2)
  423. class TestIdentityComparisonDeprecations(_DeprecationTestCase):
  424. """This tests the equal and not_equal object ufuncs identity check
  425. deprecation. This was due to the usage of PyObject_RichCompareBool.
  426. This tests that for example for `a = np.array([np.nan], dtype=object)`
  427. `a == a` it is warned that False and not `np.nan is np.nan` is returned.
  428. Should be kept in sync with TestComparisonDeprecations and new tests
  429. added when the deprecation is over. Requires only removing of @identity@
  430. (and blocks) from the ufunc loops.c.src of the OBJECT comparisons.
  431. """
  432. message = "numpy .* will not check object identity in the future."
  433. def test_identity_equality_mismatch(self):
  434. a = np.array([np.nan], dtype=object)
  435. with warnings.catch_warnings():
  436. warnings.filterwarnings('always', '', FutureWarning)
  437. assert_warns(FutureWarning, np.equal, a, a)
  438. assert_warns(FutureWarning, np.not_equal, a, a)
  439. with warnings.catch_warnings():
  440. warnings.filterwarnings('error', '', FutureWarning)
  441. assert_raises(FutureWarning, np.equal, a, a)
  442. assert_raises(FutureWarning, np.not_equal, a, a)
  443. # And the other do not warn:
  444. with np.errstate(invalid='ignore'):
  445. np.less(a, a)
  446. np.greater(a, a)
  447. np.less_equal(a, a)
  448. np.greater_equal(a, a)
  449. def test_comparison_error(self):
  450. class FunkyType(object):
  451. def __eq__(self, other):
  452. raise TypeError("I won't compare")
  453. def __ne__(self, other):
  454. raise TypeError("I won't compare")
  455. a = np.array([FunkyType()])
  456. self.assert_deprecated(np.equal, args=(a, a))
  457. self.assert_deprecated(np.not_equal, args=(a, a))
  458. def test_bool_error(self):
  459. # The comparison result cannot be interpreted as a bool
  460. a = np.array([np.array([1, 2, 3]), None], dtype=object)
  461. self.assert_deprecated(np.equal, args=(a, a))
  462. self.assert_deprecated(np.not_equal, args=(a, a))
  463. class TestAlterdotRestoredotDeprecations(_DeprecationTestCase):
  464. """The alterdot/restoredot functions are deprecated.
  465. These functions no longer do anything in numpy 1.10, so should not be
  466. used.
  467. """
  468. def test_alterdot_restoredot_deprecation(self):
  469. self.assert_deprecated(np.alterdot)
  470. self.assert_deprecated(np.restoredot)
  471. class TestBooleanIndexShapeMismatchDeprecation():
  472. """Tests deprecation for boolean indexing where the boolean array
  473. does not match the input array along the given diemsions.
  474. """
  475. message = r"boolean index did not match indexed array"
  476. def test_simple(self):
  477. arr = np.ones((5, 4, 3))
  478. index = np.array([True])
  479. #self.assert_deprecated(arr.__getitem__, args=(index,))
  480. assert_warns(np.VisibleDeprecationWarning,
  481. arr.__getitem__, index)
  482. index = np.array([False] * 6)
  483. #self.assert_deprecated(arr.__getitem__, args=(index,))
  484. assert_warns(np.VisibleDeprecationWarning,
  485. arr.__getitem__, index)
  486. index = np.zeros((4, 4), dtype=bool)
  487. #self.assert_deprecated(arr.__getitem__, args=(index,))
  488. assert_warns(np.VisibleDeprecationWarning,
  489. arr.__getitem__, index)
  490. #self.assert_deprecated(arr.__getitem__, args=((slice(None), index),))
  491. assert_warns(np.VisibleDeprecationWarning,
  492. arr.__getitem__, (slice(None), index))
  493. class TestFullDefaultDtype(object):
  494. """np.full defaults to float when dtype is not set. In the future, it will
  495. use the fill value's dtype.
  496. """
  497. def test_full_default_dtype(self):
  498. assert_warns(FutureWarning, np.full, 1, 1)
  499. assert_warns(FutureWarning, np.full, 1, None)
  500. assert_no_warnings(np.full, 1, 1, float)
  501. class TestNonCContiguousViewDeprecation(_DeprecationTestCase):
  502. """View of non-C-contiguous arrays deprecated in 1.11.0.
  503. The deprecation will not be raised for arrays that are both C and F
  504. contiguous, as C contiguous is dominant. There are more such arrays
  505. with relaxed stride checking than without so the deprecation is not
  506. as visible with relaxed stride checking in force.
  507. """
  508. def test_fortran_contiguous(self):
  509. self.assert_deprecated(np.ones((2,2)).T.view, args=(np.complex,))
  510. self.assert_deprecated(np.ones((2,2)).T.view, args=(np.int8,))
  511. if __name__ == "__main__":
  512. run_module_suite()