Skip to content
Snippets Groups Projects
Commit bf86f5f3 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Fix usages of deprecated features.

 - Scipy subnamespaces `ndimage.filters` and `ndimage.morphology` have been deprecated for a while
 - `np.trapz` is replaced by `np.trapezoid` in numpy 2.0 (https://numpy.org/doc/stable/numpy_2_0_migration_guide.html#main-namespace)
 - Path-like arguments in pytest have been switched to `pathlib` a long time ago
   (https://docs.pytest.org/en/latest/deprecations.html#fspath-argument-for-node-constructors-replaced-with-pathlib-path
    and
    https://docs.pytest.org/en/latest/deprecations.html#py-path-local-arguments-for-hooks-replaced-with-pathlib-path)
parent 942e11d7
No related branches found
No related tags found
1 merge request!174Fix usages of deprecated features.
...@@ -141,10 +141,19 @@ class IPyNbFile(pytest.File): ...@@ -141,10 +141,19 @@ class IPyNbFile(pytest.File):
pass pass
def pytest_collect_file(path, parent): if pytest_version >= 70000:
glob_exprs = ["*demo*.ipynb", "*tutorial*.ipynb", "test_*.ipynb"] # Since pytest 7.0, usage of `py.path.local` is deprecated and `pathlib.Path` should be used instead
if any(path.fnmatch(g) for g in glob_exprs): import pathlib
if pytest_version >= 50403:
return IPyNbFile.from_parent(fspath=path, parent=parent) def pytest_collect_file(file_path: pathlib.Path, parent):
else: glob_exprs = ["*demo*.ipynb", "*tutorial*.ipynb", "test_*.ipynb"]
return IPyNbFile(path, parent) if any(file_path.match(g) for g in glob_exprs):
return IPyNbFile.from_parent(path=file_path, parent=parent)
else:
def pytest_collect_file(path, parent):
glob_exprs = ["*demo*.ipynb", "*tutorial*.ipynb", "test_*.ipynb"]
if any(path.fnmatch(g) for g in glob_exprs):
if pytest_version >= 50403:
return IPyNbFile.from_parent(fspath=path, parent=parent)
else:
return IPyNbFile(path, parent)
...@@ -39,8 +39,8 @@ def circle_intersections(midpoint0, midpoint1, radius0, radius1): ...@@ -39,8 +39,8 @@ def circle_intersections(midpoint0, midpoint1, radius0, radius1):
def interface_region(concentration_arr, phase0, phase1, area=3): def interface_region(concentration_arr, phase0, phase1, area=3):
import scipy.ndimage as sc_image import scipy.ndimage as sc_image
area_phase0 = sc_image.morphology.binary_dilation(concentration_arr[..., phase0] > 0.5, iterations=area) area_phase0 = sc_image.binary_dilation(concentration_arr[..., phase0] > 0.5, iterations=area)
area_phase1 = sc_image.morphology.binary_dilation(concentration_arr[..., phase1] > 0.5, iterations=area) area_phase1 = sc_image.binary_dilation(concentration_arr[..., phase1] > 0.5, iterations=area)
return np.logical_and(area_phase0, area_phase1) return np.logical_and(area_phase0, area_phase1)
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -33,7 +33,13 @@ def _skip_instruction_sets_windows(instruction_sets): ...@@ -33,7 +33,13 @@ def _skip_instruction_sets_windows(instruction_sets):
def single_component_maxwell(x1, x2, kT, mass): def single_component_maxwell(x1, x2, kT, mass):
"""Integrate the probability density from x1 to x2 using the trapezoidal rule""" """Integrate the probability density from x1 to x2 using the trapezoidal rule"""
x = np.linspace(x1, x2, 1000) x = np.linspace(x1, x2, 1000)
return np.trapz(np.exp(-mass * x ** 2 / (2. * kT)), x) / np.sqrt(2. * np.pi * kT / mass)
try:
trapezoid = np.trapezoid # since numpy 2.0
except AttributeError:
trapezoid = np.trapz
return trapezoid(np.exp(-mass * x ** 2 / (2. * kT)), x) / np.sqrt(2. * np.pi * kT / mass)
def rr_getter(moment_group): def rr_getter(moment_group):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment