Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow square-brackets access to dataset objects #182

Merged
merged 5 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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
Expand Down
3 changes: 3 additions & 0 deletions pybop/_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading