Skip to content

Conversation

czgdp1807
Copy link
Member

Reference issue

What does this implement/fix?

In this PR, I am porting the code written in _test_fortran.f to _test_fortran_py.py. Basically, moving to Python from Fortran. AFAICT, this is an effort towards moving away from Fortran at places where Python can be used.

If needed I can use C++ instead of pure Python. Let me know.

@rgommers Let me know if this is what's expected.

Additional information

@github-actions github-actions bot added scipy.io Meson Items related to the introduction of Meson as the new build system for SciPy labels Jun 23, 2025
@lucascolley lucascolley changed the title Porting _test_fortran.f to _test_fortran_py.py MAINT: port _test_fortran.f to _test_fortran_py.py Jun 23, 2025
@lucascolley lucascolley added Fortran Items related to the internal Fortran code base and removed Meson Items related to the introduction of Meson as the new build system for SciPy labels Jun 23, 2025
@lucascolley lucascolley added this to the 1.17.0 milestone Jun 23, 2025
@lucascolley lucascolley added the maintenance Items related to regular maintenance tasks label Jun 23, 2025
Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

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

Thanks @czgdp1807. A few quick comments:

  • Why add a new .py file for this? These function can simply live in tests/test_fortran.py right?
  • It'd be good to remove the .f and .pyf files.

@ev-br would you be able to review this PR? I won't have time for the next 2 weeks at least.

@czgdp1807
Copy link
Member Author

  • Why add a new .py file for this? These function can simply live in tests/test_fortran.py right?

I don't have any strong reason to do this. Just did it for following the structure. I am +1 with having these Python functions in the same file.

  • It'd be good to remove the .f and .pyf files.

Sure thing. Removing in a few minutes.

@ilayn ilayn mentioned this pull request Jun 16, 2025
37 tasks
@ilayn
Copy link
Member

ilayn commented Jun 24, 2025

Indeed same file would be the right place for this. Marked this done in #18566 as well.

@czgdp1807 czgdp1807 marked this pull request as ready for review June 24, 2025 10:13
@czgdp1807 czgdp1807 requested a review from ev-br June 24, 2025 10:13
@czgdp1807 czgdp1807 changed the title MAINT: port _test_fortran.f to _test_fortran_py.py MAINT: port _test_fortran.f to Python functions in test_fortran.py Jun 24, 2025
Copy link
Member

@ev-br ev-br left a comment

Choose a reason for hiding this comment

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

Previously, tests were checking that a file written by FortranFile.write roundtrips with both FortranFile.read and a native Fortran file reading code. This PR removes the Fortran reader and replaces it with pure python code.
So this essentially double-checks FortranFile.read with an independent python implementation.

The code added here looks sufficiently different from https://github.com/scipy/scipy/blob/v1.16.0/scipy/io/_fortran.py#L33-L354, so it can be regareded as an independent implementation.

The format for Fortran I/O is very unlikely to change, so anything which worked in scipy 1.5 is going to keep working in the future, so removing a native Fortran reader is probably not essential. I suppose we could just remove the reader and rely on roundtripping between FortranFile reads and writes.
Now that there is an extra implementation, it does not hurt either. If anything, it could serve as simple demo of using np.fromfile on Fortran-writte files.

@czgdp1807
Copy link
Member Author

@ev-br I have addressed your review. It is ready to go now.

@ev-br ev-br merged commit c627bcc into scipy:main Jun 25, 2025
38 of 39 checks passed
@ev-br
Copy link
Member

ev-br commented Jun 25, 2025

LGTM, thank you @czgdp1807

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fortran Items related to the internal Fortran code base maintenance Items related to regular maintenance tasks scipy.io
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants