Skip to content

Commit

Permalink
Estimators should be sorted by file names (#782)
Browse files Browse the repository at this point in the history
* sort list_of_matching_files

* add test

* convertfrompattern sort files
  • Loading branch information
SzymanskiBartlomiej authored Dec 9, 2024
1 parent 694fa3c commit 54ea587
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pymchelper/input_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def frompattern(pattern: str, error: ErrorEstimate = ErrorEstimate.stderr, nan:
"""

try:
list_of_matching_files = glob(pattern)
list_of_matching_files = sorted(glob(pattern))
except TypeError as e: # noqa: F841
list_of_matching_files = pattern

Expand Down Expand Up @@ -249,7 +249,7 @@ def convertfrompattern(pattern, outputdir, converter_name, options, error=ErrorE
:param nan: if True, NaN (not a number) are excluded when averaging data.
:return:
"""
list_of_matching_files = glob(pattern)
list_of_matching_files = sorted(glob(pattern))

core_names_dict = group_input_files(list_of_matching_files)

Expand Down
15 changes: 15 additions & 0 deletions tests/test_frompattern.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
from pymchelper.input_output import frompattern


@pytest.fixture
def shieldhit_pattern() -> str:
"""Fixture for SHIELD-HIT file pattern"""
return "tests/res/shieldhit/generated/many/msh/aen_*.bdo"


def test_estimators_are_sorted_by_names(shieldhit_pattern: str) -> None:
"""Test if frompattern returns estimators sorted by name"""
averaged_estimators = frompattern(pattern=shieldhit_pattern)
estimator_names = [estimator.file_corename for estimator in averaged_estimators]
assert estimator_names == sorted(estimator_names), "Estimators are not sorted by file names"

0 comments on commit 54ea587

Please sign in to comment.