From 7ae745b9bc349a880ec660711628c6f77f2f6f1e Mon Sep 17 00:00:00 2001 From: Mark Blyth Date: Wed, 7 Feb 2024 16:00:43 +0000 Subject: [PATCH 1/3] Allow square-bracket access to datasets --- pybop/_dataset.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pybop/_dataset.py b/pybop/_dataset.py index 1263ace3e..ae3ad125a 100644 --- a/pybop/_dataset.py +++ b/pybop/_dataset.py @@ -35,6 +35,9 @@ def __init__(self, data_dictionary): self.data = data_dictionary self.names = self.data.keys() + def __getitem__(self, key): + return self.data[key] + def __repr__(self): """ Return a string representation of the Dataset instance. From db672b494a5b4aa68648b2395a6e018217e5a5d4 Mon Sep 17 00:00:00 2001 From: Mark Blyth Date: Thu, 8 Feb 2024 14:52:01 +0000 Subject: [PATCH 2/3] Add test for square-brackets dataset access --- tests/unit/test_dataset.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test_dataset.py b/tests/unit/test_dataset.py index b5cfa96dc..934e0f4ab 100644 --- a/tests/unit/test_dataset.py +++ b/tests/unit/test_dataset.py @@ -28,6 +28,7 @@ def test_dataset(self): # Test data structure assert dataset.data == data_dictionary + assert np.all(dataset["Time [s]"] == solution["Time [s]"].data) # Test exception for non-dictionary inputs with pytest.raises(ValueError): From 63c8ca319471ab697d6cd23e2a9eac4275d94fb9 Mon Sep 17 00:00:00 2001 From: Mark Blyth Date: Thu, 8 Feb 2024 14:55:26 +0000 Subject: [PATCH 3/3] Add PR description --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd9d7180c..779784c27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ ## Bug Fixes +- [#182](https://github.com/pybop-team/PyBOP/pull/182) - Allow square-brackets indexing of Dataset + # [v23.11](https://github.com/pybop-team/PyBOP/releases/tag/v23.11) - Initial release - Adds Pints, NLOpt, and SciPy optimisers