Skip to content

fix: select the newest file in last_created - #4932

Closed
Tonylo-lab wants to merge 1 commit into
ansys:mainfrom
Tonylo-lab:fix/last-created-file-selection
Closed

Tonylo-lab wants to merge 1 commit into
ansys:mainfrom
Tonylo-lab:fix/last-created-file-selection

Conversation

@Tonylo-lab

Copy link
Copy Markdown
Contributor

Description

last_created() currently returns the last filename for every nonempty input, regardless of creation times. len(set(ctimes)) is always nonzero for such inputs, so the already-computed np.argmax result is never used.

Change this condition to len(set(ctimes)) == 1. This selects the newest file when times differ while preserving the documented rule of returning the last filename when all creation times are equal.

Add 10 parameterized/edge cases in tests/test_misc.py: all six orders of three files with distinct times, three equal-time/single-file cases, and the existing empty-input error behavior.

Issue linked

This addresses a locally reproduced defect on main at 154828f; no new issue was opened. The helper is used by result-file selection, including MapdlGrpc._distributed_result_file. With a newer file0.rth and an older file0.rst, that getter currently chooses the older .rst file.

Validation

Tested on Windows, Python 3.12.15, PyMAPDL 0.74.dev0, pytest 9.1.1 and NumPy 2.5.4.

  • The same targeted selection in tests/test_misc.py gives 4 failed / 7 passed before the fix and 11 passed after it (40 unrelated cases deselected). This includes the existing real-file creation-time test.
  • The regression cases fix only the timestamp helper's return values for deterministic cross-platform testing and execute the real selection function.
  • A separate probe creates three real files with distinct Windows creation times. The original selects correctly for 2 of their 6 permutations; the fix selects correctly for all 6.
  • The same probe exercises the actual _distributed_result_file getter with a minimal local context and real files: it selects the older .rst before the fix and the newer .rth afterward. These are synthetic files, with no MAPDL connection or solver-generated contents.
  • last_created() has 100% line and branch coverage (5 statements and 2 branches).
  • All 15 pre-commit hooks applicable to the two changed files pass, including mypy, numpydoc, Black, isort, flake8, Bandit, spelling, license and text checks.
  • git diff --check passes, and the final patch matches the reviewed draft exactly.

Known baseline check failure: full pre-commit run --all-files stops at src/ansys/mapdl/core/errors.py:601: Module has no attribute "SIGKILL". Windows does not provide signal.SIGKILL. The same single error reproduces on unmodified 154828f (325 source files checked); it is tracked separately in #4903 / #4904. This PR does not change that code.

Not run: MAPDL live-server/solver tests or the full test suite. No MAPDL process was launched.

Checklist

  • Tested the change locally and added regression tests.
  • Verified the changed function's coverage and applicable checks.
  • Reviewed the complete two-file diff.
  • Followed the branch and PR naming conventions.
  • The existing docstring already specifies the intended behavior; no documentation or hand-written changelog fragment is needed for this correction.

Prepared and verified with assistance from Codex.

@Tonylo-lab
Tonylo-lab requested a review from a team as a code owner November 15, 2026 02:45

@germa89 germa89 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Thank you @Tonylo-lab !

if len(set(ctimes)) == 1:
return filenames[-1]

return filenames[idx]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It probably makes more sense to get the idx after checking the length.

    ctimes = [creation_time(filename) for filename in filenames]

    if len(set(ctimes)) == 1:
        return filenames[-1]

    idx = np.argmax(ctimes)
    return filenames[idx]

@germa89

germa89 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

@pyansys-ci-bot migrate

@pyansys-ci-bot

Copy link
Copy Markdown
Contributor

🚀 Migration completed!

The pull request #4967 has been created successfully.

Thank you @Tonylo-lab for your contribution! Please review the new PR and make any necessary changes.

This PR will be closed by the admins soon.

You can now start to work in the new pull request by cloning this pull request branch in a new repository by doing:

git clone -b migration/pr-4932 --single-branch https://github.com/ansys/pymapdl.git

If you have GitHub CLI installed, you can also use the following command to check out the pull request:

gh pr checkout https://github.com/ansys/pymapdl/pull/4932

Thank you again for your contribution @Tonylo-lab!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants