Repository: aeye-lab/pymovements
Pull request #1022 (2025-03-12 13:31:24)

feat: add DatasetLibrary.names()
## Description

Adds `DatasetLibrary.names()` which lists all names of added datasets.

## Type of change

- [x] New feature (non-breaking change which adds functionality)

## How Has This Been Tested?

- [x] Test that number of datasets is greater than 0
- [x] Test that `DatasetLibrary.names()` returns list of strings

## Checklist:

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published in downstream modules
- [x] I have checked my code and corrected any misspellings


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/aeye-lab/pymovements/pull/1022?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 99.94%. Comparing base [(`ff76f47`)](https://app.codecov.io/gh/aeye-lab/pymovements/commit/ff76f47b584b4ff75fb727d6a66ace26b8f6fb03?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab) to head [(`5d3183f`)](https://app.codecov.io/gh/aeye-lab/pymovements/commit/5d3183fd38e8b6a532d0fe9943e97379c7fbb0c5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab).

<details><summary>Additional details and impacted files</summary>


```diff
@@             Coverage Diff             @@
##              main    #1022      +/-   ##
===========================================
- Coverage   100.00%   99.94%   -0.06%     
===========================================
  Files           78       78              
  Lines         3561     3564       +3     
  Branches       629      629              
===========================================
+ Hits          3561     3562       +1     
- Misses           0        1       +1     
- Partials         0        1       +1     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/aeye-lab/pymovements/pull/1022?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aeye-lab).

<details><summary>🚀 New features to boost your workflow: </summary>

- ❄ [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
SiQube: I have a similar function in #914 .available_datasets() but list is probably nicer
dkrako: > I have a similar function in #914 .available_datasets() but list is probably nicer

Yes, `list()` is nicer, but there's some ambiguity left : does this return a list of dataset definitions or a list of names?

Instead I renamed this to `DatasetLibrary.names()`.

I also wanted to add the `@property` decorator, but python3.13 removed the ability to combine `@classmethod` decorators with `@property`. I really don't get why they introduce all these breaking changes.. it would've been so nice.
dkrako: I created the followup PR #1024 such that we can treat this issue separately.

Patch:
diff --git a/src/pymovements/dataset/dataset_library.py b/src/pymovements/dataset/dataset_library.py
index 69a9532..2af4e18 100644
--- a/src/pymovements/dataset/dataset_library.py
+++ b/src/pymovements/dataset/dataset_library.py
@@ -63,6 +63,17 @@ class DatasetLibrary:
         """
         return cls.definitions[name]
 
+    @classmethod
+    def names(cls) -> list[str]:
+        """Get list of names of all added datasets that are included in the library.
+
+        Returns
+        -------
+        list[str]
+            List of dataset names that are included in the dataset library.
+        """
+        return sorted(list(cls.definitions.keys()))
+
 
 DatsetDefinitionClass = TypeVar('DatsetDefinitionClass', bound=type[DatasetDefinition])
 


Test patch:
diff --git a/tests/unit/dataset/dataset_library_test.py b/tests/unit/dataset/dataset_library_test.py
index e584da8..c312f08 100644
--- a/tests/unit/dataset/dataset_library_test.py
+++ b/tests/unit/dataset/dataset_library_test.py
@@ -46,3 +46,16 @@ def test_add_two_defintions():
 
     assert definition1 == CustomDatasetDefinition1
     assert definition2 == CustomDatasetDefinition2
+
+
+def test_library_not_empty():
+    assert len(pm.DatasetLibrary.definitions) >= 0
+
+
+def test_list_names_is_list_of_str():
+    names = pm.DatasetLibrary.names()
+
+    assert isinstance(names, list)
+
+    for name in names:
+        assert isinstance(name, str)