From 11496885a403bf1a8577ea76338fa062ba94146a Mon Sep 17 00:00:00 2001 From: Radonirinaunimi Date: Wed, 30 Oct 2024 23:15:34 +0100 Subject: [PATCH] Add missed `PyGrid.set_key_value` back --- pineappl_py/src/grid.rs | 17 +++++++++++++++++ pineappl_py/tests/test_grid.py | 10 ++++++++++ 2 files changed, 27 insertions(+) diff --git a/pineappl_py/src/grid.rs b/pineappl_py/src/grid.rs index 549f5590..6d250264 100644 --- a/pineappl_py/src/grid.rs +++ b/pineappl_py/src/grid.rs @@ -209,6 +209,23 @@ impl PyGrid { self.grid.set_remapper(remapper.bin_remapper).unwrap(); } + /// Set a metadata key-value pair in the grid. + /// + /// # Panics + /// TODO + /// + /// Parameters + /// ---------- + /// key : str + /// key + /// value : str + /// value + pub fn set_key_value(&mut self, key: &str, value: &str) { + self.grid + .metadata_mut() + .insert(key.to_owned(), value.to_owned()); + } + /// Convolve the grid with as many distributions. /// /// # Panics diff --git a/pineappl_py/tests/test_grid.py b/pineappl_py/tests/test_grid.py index e766f0e0..2f4a3dba 100644 --- a/pineappl_py/tests/test_grid.py +++ b/pineappl_py/tests/test_grid.py @@ -400,6 +400,16 @@ def test_io(self, tmp_path, fake_grids): assert isinstance(gg, Grid) _ = Grid.read(str(p)) + def test_set_key_value(self, fake_grids): + g = fake_grids.grid_with_two_convolutions( + channels=CHANNELS, + orders=ORDERS, + convolutions=[CONVOBJECT, CONVOBJECT], + ) + g.set_key_value("bla", "blub") + g.set_key_value('"', "'") + g.set_key_value("äöü", "ß\\") + def test_fill(self, fake_grids): g = fake_grids.grid_with_two_convolutions( channels=CHANNELS,