|
1 | 1 | """Contains routines to monkey patch or provide alternatives to upstream code
|
2 |
| -which may need changes for compatibility. |
| 2 | +which may need changes for compatibility, or check versions. |
3 | 3 | """
|
4 | 4 |
|
5 | 5 | import numpy as np
|
| 6 | +from numpy.lib import NumpyVersion |
6 | 7 |
|
7 |
| -_numpy_version = np.lib.NumpyVersion(np.version.version) |
8 |
| -_patches = { |
9 |
| - 'numpy_formatters': { |
10 |
| - 'applied': False, |
11 |
| - 'required': _numpy_version < np.lib.NumpyVersion('1.13.0'), |
12 |
| - }, |
13 |
| -} |
| 8 | +from pydrake.common.deprecation import _warn_deprecated |
14 | 9 |
|
15 | 10 |
|
16 |
| -def _defer_callable_type(cls): |
17 |
| - # Makes a type, which is meant to purely callable, and defers its |
18 |
| - # construction until it needs to be called. |
| 11 | +def check_required_numpy_version(_actual=np.version.version): |
| 12 | + """Fails fast if a minimum version of NumPy is not present. |
19 | 13 |
|
20 |
| - class Deferred(object): |
21 |
| - def __init__(self, *args, **kwargs): |
22 |
| - self._args = args |
23 |
| - self._kwargs = kwargs |
24 |
| - self._obj = None |
| 14 | + pydrake requires NumPy >= 0.15.0 namely for the following patches: |
| 15 | + https://github.com/numpy/numpy/pull/10898 |
| 16 | + https://github.com/numpy/numpy/pull/11076 |
25 | 17 |
|
26 |
| - def _get_obj(self): |
27 |
| - if self._obj is None: |
28 |
| - self._obj = cls(*self._args, **self._kwargs) |
29 |
| - return self._obj |
30 |
| - |
31 |
| - def __call__(self, *args, **kwargs): |
32 |
| - return self._get_obj().__call__(*args, **kwargs) |
33 |
| - |
34 |
| - return Deferred |
| 18 | + If Drake uses user-dtypes in lieu of `dtype=object`, then anything that |
| 19 | + refers to `autodiff` or `symbolic` (e.g. all of `systems`, |
| 20 | + `multibody`, etc.) could potentially have "random" segfaults. |
| 21 | + """ |
| 22 | + actual = NumpyVersion(_actual) |
| 23 | + minimum = NumpyVersion('1.15.0') |
| 24 | + if actual < minimum: |
| 25 | + raise RuntimeError( |
| 26 | + "pydrake requires numpy >= {}, but only {} is present".format( |
| 27 | + minimum.vstring, actual.vstring)) |
35 | 28 |
|
36 | 29 |
|
37 | 30 | def maybe_patch_numpy_formatters():
|
38 |
| - """Required to permit printing of symbolic array types in NumPy < 1.13.0. |
39 |
| -
|
40 |
| - See #8729 for more information. |
41 |
| - """ |
42 |
| - # Provides version-dependent monkey-patch which effectively achieves a |
43 |
| - # portion of https://github.com/numpy/numpy/pull/8963 |
44 |
| - patch = _patches['numpy_formatters'] |
45 |
| - if not patch['required']: |
46 |
| - return |
47 |
| - if patch['applied']: |
48 |
| - return |
49 |
| - module = np.core.arrayprint |
50 |
| - defer_callable_types = [ |
51 |
| - 'IntegerFormat', |
52 |
| - 'FloatFormat', |
53 |
| - ] |
54 |
| - for name in defer_callable_types: |
55 |
| - original = getattr(module, name) |
56 |
| - deferred = _defer_callable_type(original) |
57 |
| - setattr(module, name, deferred) |
58 |
| - patch['applied'] = True |
| 31 | + """Deprecated functionality.""" |
| 32 | + _warn_deprecated( |
| 33 | + "`maybe_patch_numpy_formatters` is no longer needed, and will " |
| 34 | + "be removed after 2019/01", stacklevel=3) |
0 commit comments