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

Dict-like methods of Dataset. #153

Merged
merged 17 commits into from
Oct 6, 2023
Merged

Dict-like methods of Dataset. #153

merged 17 commits into from
Oct 6, 2023

Conversation

YooSunYoung
Copy link
Collaborator

@YooSunYoung YooSunYoung commented Sep 29, 2023

Fixes #76
During the sprint

Dict-like methods:

  • keys
  • values
  • items
  • __getitem__
  • __setitem__
  • setdefault We decided not to include this one.

Helper method to check if the key to the __(get/set)item__ is valid:

  • _validate_field_name

keys/values/items

keys return names of fields that belong to the current type of the Dataset object and other fields that only belong to the other type only if they are not None.

values and items are using keys, hence using same set of fields.

__getitem__/__setitem__/setdefault

These methods check if the key(field_name) is one of names of fields defined in the DatasetBase._FIELD_SPEC.

If not valid, raise KeyError with custom error message.

But these methods don't check if they are valid fields of the current type.

Manual fields

Fields that are not defined in the DatasetBase._FIELD_SPEC are excluded for now. See #151 for more detail.

@YooSunYoung YooSunYoung added the sprint-scipp-2023-09 Sprint of the Scipp team label Oct 2, 2023
@YooSunYoung YooSunYoung self-assigned this Oct 2, 2023
@YooSunYoung YooSunYoung marked this pull request as ready for review October 2, 2023 11:11
src/scitacean/dataset.py Outdated Show resolved Hide resolved
def keys(self) -> Iterable[str]:
"""Dict-like keys(names of fields) method.

.. versionadded:: RELEASE_PLACEHOLDER
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move those directives to the very end of the docstring.

Copy link
Collaborator Author

@YooSunYoung YooSunYoung Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jl-wynen
image

It seems like it doesn't work if it is not above the sub-titles...?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an annoyance with restructured text. You need two empty lines to 'return' from the previous section. I just added this to the coding conventions: https://github.com/SciCatProject/scitacean/blob/main/docs/developer/coding-conventions.rst

src/scitacean/dataset.py Outdated Show resolved Hide resolved
src/scitacean/dataset.py Outdated Show resolved Hide resolved
tests/dataset_test.py Outdated Show resolved Hide resolved
@jl-wynen
Copy link
Collaborator

jl-wynen commented Oct 3, 2023

Can you add a release note?

@YooSunYoung
Copy link
Collaborator Author

@jl-wynen I'm not authorized to merge this PR...!

@jl-wynen jl-wynen merged commit 98e3c13 into main Oct 6, 2023
13 checks passed
@jl-wynen jl-wynen deleted the dict-like-methods branch October 6, 2023 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sprint-scipp-2023-09 Sprint of the Scipp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dict-like API for Dataset
2 participants