Skip to content

Commit

Permalink
Increase minimum numpy version to 1.21 (#3983)
Browse files Browse the repository at this point in the history
* Increase minimum numpy version to 1.21
* ndarray to npt.NDArray typing for various MDAnalysis.lib modules
  • Loading branch information
IAlibay authored Jan 20, 2023
1 parent 130e862 commit f966ec2
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gh-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
full-deps: false
install_hole: false
codecov: false
numpy: numpy=1.20.0
numpy: numpy=1.21.0
- name: asv_check
os: ubuntu-latest
python-version: 3.8
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
with:
mamba: true
full-deps: true
numpy: numpy=1.20.0
numpy: numpy=1.21.0

- name: install
run: |
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ matrix:
group: edge
if: type = cron
before_install:
- python -m pip install cython "numpy>=1.20.0" scipy
- python -m pip install cython "numpy>=1.21.0" scipy
- python -m pip install --no-build-isolation hypothesis matplotlib packaging pytest pytest-cov pytest-xdist tqdm threadpoolctl fasteners
install:
- cd package
Expand Down
6 changes: 3 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
PYTHON_VERSION: '3.8'
PYTHON_ARCH: 'x86'
BUILD_TYPE: 'normal'
NUMPY_MIN: '1.20.0'
NUMPY_MIN: '1.21.0'
imageName: 'windows-2019'
Win-Python38-64bit-full:
PYTHON_VERSION: '3.8'
Expand All @@ -47,7 +47,7 @@ jobs:
PYTHON_VERSION: '3.8'
PYTHON_ARCH: 'x64'
BUILD_TYPE: 'wheel'
NUMPY_MIN: '1.20.0'
NUMPY_MIN: '1.21.0'
imageName: 'windows-2019'
Linux-Python310-64bit-full-wheel:
PYTHON_VERSION: '3.10'
Expand All @@ -59,7 +59,7 @@ jobs:
PYTHON_VERSION: '3.8'
PYTHON_ARCH: 'x64'
BUILD_TYPE: 'wheel'
NUMPY_MIN: '1.20.0'
NUMPY_MIN: '1.21.0'
imageName: 'ubuntu-latest'
pool:
vmImage: $(imageName)
Expand Down
2 changes: 1 addition & 1 deletion maintainer/conda/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
- mmtf-python
- mock
- networkx
- numpy>=1.20
- numpy>=1.21
- pytest
- python==3.8
- pytng>=0.2.3
Expand Down
3 changes: 3 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Enhancements
and SegmentGroup. (PR #3953)

Changes
* As per NEP29 the minimum supported NumPy version has been raised to 1.21
(note: in practice later versions of NumPy may be used depending on your
architecture, operating system, or Python version) (PR #3983)
* The deprecated direct indexing and `times` from the `results` attribute of
analysis.nucleicacids' NucPairDist and WatsonCrickDist classes has been
removed. Please use the `results.pair_distances` and `times` attributes
Expand Down
132 changes: 62 additions & 70 deletions package/MDAnalysis/lib/distances.py

Large diffs are not rendered by default.

21 changes: 8 additions & 13 deletions package/MDAnalysis/lib/mdamath.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def norm(v: npt.ArrayLike) -> float:
return np.sqrt(np.dot(v, v))


# typing: numpy
def normal(vec1: npt.ArrayLike, vec2: npt.ArrayLike) -> np.ndarray:
def normal(vec1: npt.ArrayLike, vec2: npt.ArrayLike) -> npt.NDArray:
r"""Returns the unit vector normal to two vectors.
.. math::
Expand All @@ -105,16 +104,15 @@ def normal(vec1: npt.ArrayLike, vec2: npt.ArrayLike) -> np.ndarray:
.. versionchanged:: 0.11.0
Moved into lib.mdamath
"""
normal = np.cross(vec1, vec2)
normal: npt.NDArray = np.cross(vec1, vec2)
n = norm(normal)
if n == 0.0:
return normal # returns [0,0,0] instead of [nan,nan,nan]
# ... could also use numpy.nan_to_num(normal/norm(normal))
return normal / n


# typing: numpy
def pdot(a: npt.ArrayLike, b: npt.ArrayLike) -> np.ndarray:
def pdot(a: npt.NDArray, b: npt.NDArray) -> npt.NDArray:
"""Pairwise dot product.
``a`` must be the same shape as ``b``.
Expand All @@ -131,8 +129,7 @@ def pdot(a: npt.ArrayLike, b: npt.ArrayLike) -> np.ndarray:
return np.einsum('ij,ij->i', a, b)


# typing: numpy
def pnorm(a: npt.ArrayLike) -> np.ndarray:
def pnorm(a: npt.NDArray) -> npt.NDArray:
"""Euclidean norm of each vector in a matrix
Parameters
Expand Down Expand Up @@ -199,8 +196,7 @@ def dihedral(ab: npt.ArrayLike, bc: npt.ArrayLike, cd: npt.ArrayLike) -> float:
return (x if stp(ab, bc, cd) <= 0.0 else -x)


# typing: numpy
def sarrus_det(matrix: np.ndarray) -> Union[float, np.ndarray]:
def sarrus_det(matrix: npt.NDArray) -> Union[float, npt.NDArray]:
"""Computes the determinant of a 3x3 matrix according to the
`rule of Sarrus`_.
Expand Down Expand Up @@ -245,8 +241,7 @@ def sarrus_det(matrix: np.ndarray) -> Union[float, np.ndarray]:
return _sarrus_det_multiple(m.reshape((-1, 3, 3))).reshape(shape[:-2])


# typing: numpy
def triclinic_box(x: npt.ArrayLike, y: npt.ArrayLike, z: npt.ArrayLike) -> np.ndarray:
def triclinic_box(x: npt.ArrayLike, y: npt.ArrayLike, z: npt.ArrayLike) -> npt.NDArray:
"""Convert the three triclinic box vectors to
``[lx, ly, lz, alpha, beta, gamma]``.
Expand Down Expand Up @@ -308,8 +303,8 @@ def triclinic_box(x: npt.ArrayLike, y: npt.ArrayLike, z: npt.ArrayLike) -> np.nd
return np.zeros(6, dtype=np.float32)


# typing: numpy
def triclinic_vectors(dimensions: npt.ArrayLike, dtype: npt.DTypeLike = np.float32) -> np.ndarray:
def triclinic_vectors(dimensions: npt.ArrayLike,
dtype: npt.DTypeLike = np.float32) -> npt.NDArray:
"""Convert ``[lx, ly, lz, alpha, beta, gamma]`` to a triclinic matrix
representation.
Expand Down
9 changes: 3 additions & 6 deletions package/MDAnalysis/lib/pkdtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ def set_coords(self, coords: npt.ArrayLike, cutoff: Optional[float] = None) -> N
self.ckdt = cKDTree(self.coords, self.leafsize)
self._built = True

# typing: numpy
def search(self, centers: npt.ArrayLike, radius: float) -> np.ndarray:
def search(self, centers: npt.ArrayLike, radius: float) -> npt.NDArray:
"""Search all points within radius from centers and their periodic images.
All the centers coordinates are wrapped around the central cell
Expand Down Expand Up @@ -210,8 +209,7 @@ def search(self, centers: npt.ArrayLike, radius: float) -> np.ndarray:
self._indices = np.asarray(unique_int_1d(self._indices))
return self._indices

# typing: numpy
def get_indices(self) -> np.ndarray:
def get_indices(self) -> npt.NDArray:
"""Return the neighbors from the last query.
Returns
Expand All @@ -221,8 +219,7 @@ def get_indices(self) -> np.ndarray:
"""
return self._indices

# typing: numpy
def search_pairs(self, radius: float) -> np.ndarray:
def search_pairs(self, radius: float) -> npt.NDArray:
"""Search all the pairs within a specified radius
Parameters
Expand Down
8 changes: 4 additions & 4 deletions package/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ requires = [
# lowest NumPy we can use for a given Python,
# In part adapted from: https://github.com/scipy/oldest-supported-numpy/blob/main/setup.cfg
# except for more exotic platform (Mac Arm flavors)
# aarch64, AIX, s390x all support < 1.20 so we can safely pin to this
# aarch64, AIX, s390x all support < 1.21 so we can safely pin to this
# Note: MDA does not build with PyPy so we do not support it in the build system
"numpy==1.20.0; python_version=='3.8' and (platform_machine!='arm64' or platform_system!='Darwin') and platform_python_implementation != 'PyPy'",
"numpy==1.20.0; python_version=='3.9' and (platform_machine!='arm64' or platform_system!='Darwin') and platform_python_implementation != 'PyPy'",
"numpy==1.21.0; python_version=='3.8' and (platform_machine!='arm64' or platform_system!='Darwin') and platform_python_implementation != 'PyPy'",
"numpy==1.21.0; python_version=='3.9' and (platform_machine!='arm64' or platform_system!='Darwin') and platform_python_implementation != 'PyPy'",
# arm64 on darwin for py3.8+ requires numpy >=1.21.0
"numpy==1.21.0; python_version=='3.8' and platform_machine=='arm64' and platform_system=='Darwin' and platform_python_implementation != 'PyPy'",
"numpy==1.21.0; python_version=='3.9' and platform_machine=='arm64' and platform_system=='Darwin' and platform_python_implementation != 'PyPy'",
Expand Down Expand Up @@ -39,7 +39,7 @@ maintainers = [
]
requires-python = ">=3.8"
dependencies = [
'numpy>=1.20.0',
'numpy>=1.21.0',
'biopython>=1.80',
'networkx>=2.0',
'GridDataFormats>=0.4.0',
Expand Down
2 changes: 1 addition & 1 deletion package/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mmtf-python
msmb_theme==1.2.0
netcdf4
networkx
numpy>=1.20.0
numpy>=1.21.0
packaging
parmed
pytest
Expand Down
6 changes: 3 additions & 3 deletions package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def get_numpy_include():
import numpy as np
except ImportError:
print('*** package "numpy" not found ***')
print('MDAnalysis requires a version of NumPy (>=1.20.0), even for setup.')
print('MDAnalysis requires a version of NumPy (>=1.21.0), even for setup.')
print('Please get it from http://numpy.scipy.org/ or install it through '
'your package manager.')
sys.exit(-1)
Expand Down Expand Up @@ -593,7 +593,7 @@ def long_description(readme):
exts, cythonfiles = extensions(config)

install_requires = [
'numpy>=1.20.0',
'numpy>=1.21.0',
'biopython>=1.80',
'networkx>=2.0',
'GridDataFormats>=0.4.0',
Expand Down Expand Up @@ -641,7 +641,7 @@ def long_description(readme):
# all standard requirements are available through PyPi and
# typically can be installed without difficulties through setuptools
setup_requires=[
'numpy>=1.20.0',
'numpy>=1.21.0',
'packaging',
],
install_requires=install_requires,
Expand Down

0 comments on commit f966ec2

Please sign in to comment.