From 4d4e256a317346333926e138991cc4de9bfd95a7 Mon Sep 17 00:00:00 2001 From: Johannes Kasimir Date: Fri, 7 Aug 2026 12:19:59 +0200 Subject: [PATCH 1/3] docs: deprecate convert --- pyproject.toml | 2 ++ src/scippneutron/core/conversions.py | 14 ++++++++++++++ tests/convert_test.py | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 42548bb1c..bda66212d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,6 +80,8 @@ addopts = """ testpaths = "tests" filterwarnings = [ "error", + # Legacy conversion tests intentionally exercise this deprecated API. + 'ignore:scippneutron.convert is deprecated:scipp.VisibleDeprecationWarning', 'ignore:You are running a "Debug" build of scipp:', # from ipywidgets; they are migrating away from ipykernel, this warning should go away 'ignore:The `ipykernel.comm.Comm` class has been deprecated.:DeprecationWarning', diff --git a/src/scippneutron/core/conversions.py b/src/scippneutron/core/conversions.py index 0b7736471..94d72abd7 100644 --- a/src/scippneutron/core/conversions.py +++ b/src/scippneutron/core/conversions.py @@ -2,6 +2,7 @@ # Copyright (c) 2023 Scipp contributors (https://github.com/scipp) # @author Jan-Lukas Wynen +import warnings from collections.abc import Callable import scipp as sc @@ -140,8 +141,21 @@ def convert( :seealso: :py:func:`scippneutron.deduce_conversion_graph` and :py:func:`scippneutron.conversion_graph` to inspect the possible conversions. + + .. deprecated:: 26.8.0 + Use :py:meth:`scipp.DataArray.transform_coords` or + :py:meth:`scipp.Dataset.transform_coords` with a graph from + :py:mod:`scippneutron.conversion.graph` instead. """ + warnings.warn( + "scippneutron.convert is deprecated and will be removed in a future " + "release. Use scipp.transform_coords with a graph from " + "scippneutron.conversion.graph instead.", + sc.VisibleDeprecationWarning, + stacklevel=2, + ) + graph = deduce_conversion_graph(data, origin, target, scatter) try: diff --git a/tests/convert_test.py b/tests/convert_test.py index 91678263a..fadafe4f1 100644 --- a/tests/convert_test.py +++ b/tests/convert_test.py @@ -88,6 +88,16 @@ def make_test_data(coords=(), dataset=False): return da +def test_convert_is_deprecated(): + tof = make_test_data(coords=('tof', 'Ltotal')) + with pytest.warns( + sc.VisibleDeprecationWarning, + match=r'scippneutron\.convert is deprecated.*scipp\.transform_coords', + ) as warnings: + scn.convert(tof, origin='tof', target='wavelength', scatter=True) + assert warnings[0].filename == __file__ + + def make_tof_binned_events(): buffer = sc.DataArray( sc.zeros(dims=['event'], shape=[7], dtype=float), From 547f5859637063a1d1e517897f1c0ce5f058d3ca Mon Sep 17 00:00:00 2001 From: Johannes Kasimir Date: Wed, 19 Aug 2026 09:43:58 +0200 Subject: [PATCH 2/3] test: move filter to convert_test.py --- pyproject.toml | 2 -- tests/convert_test.py | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index bda66212d..42548bb1c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,8 +80,6 @@ addopts = """ testpaths = "tests" filterwarnings = [ "error", - # Legacy conversion tests intentionally exercise this deprecated API. - 'ignore:scippneutron.convert is deprecated:scipp.VisibleDeprecationWarning', 'ignore:You are running a "Debug" build of scipp:', # from ipywidgets; they are migrating away from ipykernel, this warning should go away 'ignore:The `ipykernel.comm.Comm` class has been deprecated.:DeprecationWarning', diff --git a/tests/convert_test.py b/tests/convert_test.py index fadafe4f1..1339b8a28 100644 --- a/tests/convert_test.py +++ b/tests/convert_test.py @@ -11,6 +11,10 @@ import scippneutron as scn +pytestmark = pytest.mark.filterwarnings( + 'ignore:scippneutron.convert is deprecated:scipp.VisibleDeprecationWarning' +) + def make_source_position(): return sc.vector(value=[0.0, 0.0, -10.0], unit='m') From 32bc1bf9fd23f42e4b603bf3e195bd7564a99722 Mon Sep 17 00:00:00 2001 From: Johannes Kasimir Date: Wed, 19 Aug 2026 10:18:00 +0200 Subject: [PATCH 3/3] refactor: use transform coords instead of convert --- .../neutron_convert_units_test.py | 40 ++++++++++++++++--- tests/mantid_test.py | 20 +++++++++- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/tests/mantid_scipp_comparison/neutron_convert_units_test.py b/tests/mantid_scipp_comparison/neutron_convert_units_test.py index 165f1bccb..2d0c524fd 100644 --- a/tests/mantid_scipp_comparison/neutron_convert_units_test.py +++ b/tests/mantid_scipp_comparison/neutron_convert_units_test.py @@ -79,7 +79,15 @@ def test_mantid_convert_tof_to_wavelength(): out_mantid = mantid_convert_units(in_ws, 'wavelength') in_da = scn.mantid.from_mantid(in_ws)['data'] - out_scipp = scn.convert(data=in_da, origin='tof', target='wavelength', scatter=True) + out_scipp = in_da.transform_coords( + 'wavelength', + graph=scn.conversion_graph( + origin='tof', + target='wavelength', + scatter=True, + energy_mode='elastic', + ), + ) assert sc.allclose( out_scipp.coords['wavelength'], @@ -94,7 +102,15 @@ def test_mantid_convert_tof_to_dspacing(): out_mantid = mantid_convert_units(in_ws, 'dspacing') in_da = scn.mantid.from_mantid(in_ws)['data'] - out_scipp = scn.convert(data=in_da, origin='tof', target='dspacing', scatter=True) + out_scipp = in_da.transform_coords( + 'dspacing', + graph=scn.conversion_graph( + origin='tof', + target='dspacing', + scatter=True, + energy_mode='elastic', + ), + ) assert sc.allclose( out_scipp.coords['dspacing'], @@ -109,7 +125,15 @@ def test_mantid_convert_tof_to_energy(): out_mantid = mantid_convert_units(in_ws, 'energy') in_da = scn.mantid.from_mantid(in_ws)['data'] - out_scipp = scn.convert(data=in_da, origin='tof', target='energy', scatter=True) + out_scipp = in_da.transform_coords( + 'energy', + graph=scn.conversion_graph( + origin='tof', + target='energy', + scatter=True, + energy_mode='elastic', + ), + ) # Mantid reverses the order of the energy dim. mantid_energy = sc.empty_like(out_mantid.coords['energy']) @@ -130,8 +154,14 @@ def test_mantid_convert_tof_to_direct_energy_transfer(): ) in_da = scn.mantid.from_mantid(in_ws)['data'] - out_scipp = scn.convert( - data=in_da, origin='tof', target='energy_transfer', scatter=True + out_scipp = in_da.transform_coords( + 'energy_transfer', + graph=scn.conversion_graph( + origin='tof', + target='energy_transfer', + scatter=True, + energy_mode='direct_inelastic', + ), ) # The conversion consists of multiplications and additions, thus the relative error diff --git a/tests/mantid_test.py b/tests/mantid_test.py index 55c48430e..2d2b6f7be 100644 --- a/tests/mantid_test.py +++ b/tests/mantid_test.py @@ -169,7 +169,15 @@ def test_unit_conversion(self): )['data'] da = da.hist(tof=target_tof) d = sc.Dataset(data={da.name: da}) - converted = scn.convert(d, 'tof', 'wavelength', scatter=True) + converted = d.transform_coords( + 'wavelength', + graph=scn.conversion_graph( + origin='tof', + target='wavelength', + scatter=True, + energy_mode='elastic', + ), + ) assert sc.allclose( converted_mantid['data'].data, converted[""].data.to(dtype='float64') @@ -203,7 +211,15 @@ def test_inelastic_unit_conversion(self): da.coords['position'] *= np.sqrt(scale) low_tof = da.bins.constituents['data'].coords['tof'] < 49000.0 * sc.units.us da.coords['incident_energy'] = 3.0 * sc.units.meV - da = scn.convert(da, 'tof', 'energy_transfer', scatter=True) + da = da.transform_coords( + 'energy_transfer', + graph=scn.conversion_graph( + origin='tof', + target='energy_transfer', + scatter=True, + energy_mode='direct_inelastic', + ), + ) assert sc.all( sc.isnan(da.coords['energy_transfer']) | sc.isclose(