Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1085 +/- ##
==========================================
+ Coverage 68.52% 68.66% +0.14%
==========================================
Files 396 396
Lines 12746 12803 +57
Branches 1376 1381 +5
==========================================
+ Hits 8734 8791 +57
Misses 4012 4012 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for this @fiolj. Would you mind reverting the changes not related to the implementation? (styling) There are too many and it renders difficult to read through the PR. You can check the style_guide for info https://github.com/fortran-lang/stdlib/blob/master/STYLE_GUIDE.md One thing, white spaces in-between parentheses and an intrinsic function are not recommended ( |
|
Thanks @jalvesz, I've fixed the formatting |
|
|
||
| s = open(filename, "w") | ||
| !! Write the header if non-empty | ||
| ! prepend function may be replaced by use of replace_all but currently stdlib_strings |
There was a problem hiding this comment.
It is probably something that we should solve at a later stage.
|
Reviewing the arguments of Currently, we have the order of |
As |
Thanks, I agree. Last uploaded commit has the new order and some small cleanup of the code. I think that it this version is close to apt to be merged, except for the codecov failings (which I have no idea what they mean). |
It is related to the examples that are not covered by these pipelines. I think that @jalvesz got a similar issue with another PR. |
|
The fails with codecov are valid in my opinion. In #1074 we avoided codecov from analyzing the examples as a metric for coverage. But in this case, it is a valid fail because there are API changes which are not being tested. It is not enough to just add an example to ensure correctness. |
I am confused. This shows that some lines of
I agree with you. |
Co-authored-by: Jeremie Vandenplas <jeremie.vandenplas@gmail.com>
@fiolj could you update the tests to cover the different changes in the API? |
Yes. I've commited some tests. |
I'm also confused now, codecov is supposed to ignore files in the examples directory after the PR #1074 ... I would say for the moment to ignore this false error. |
There was a problem hiding this comment.
Pull request overview
This PR adds optional arguments to the savetxt function to provide more flexibility when saving 2D arrays to text files, making it more similar to NumPy's savetxt functionality.
Changes:
- Added ability to specify an already-opened file unit instead of a filename, enabling writing to stdout or appending to files
- Added optional
headerandfooterparameters that are automatically commented with a configurable comment character - Added optional
fmtparameter to customize output format - Modified format string construction to support custom delimiters (though delimiter parameter still limited to single character)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 18 comments.
| File | Description |
|---|---|
| src/io/stdlib_io.fypp | Core implementation: generates two variants of savetxt (filename and unit), adds format customization, header/footer support via new prepend helper function |
| test/io/test_savetxt.f90 | Updated tests to exercise new delimiter, fmt, header, footer, and comments parameters |
| doc/specs/stdlib_io.md | Updated documentation to describe new optional parameters and unit-based interface |
| example/io/example_savetxt.f90 | Added examples demonstrating new features including writing to stdout |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
doc/specs/stdlib_io.md
Outdated
| `delimiter` (optional): Shall be a character expression of length 1 that contains the delimiter used to separate the columns. The default is `' '`. | ||
| `delimiter` (optional): Shall be a character expression of any length that contains the delimiter used to separate the columns. The default is a single space `' '`. | ||
|
|
||
| `fmt`: (optional): Fortran format specifier for the text save. Defaults to the write format for the data type. |
There was a problem hiding this comment.
It currently is (and was also in the original) the (may be little) documented Formatting constants. I've added the reference now in the spec
| !! | ||
| !! Saves a 2D array into a text file | ||
| !! ([Specification](../page/specs/stdlib_io.html#description_2)) | ||
| #:for a1 in ['f', 'u'] |
There was a problem hiding this comment.
| #:for a1 in ['f', 'u'] | |
| #:for arg1 in ['f'ilename, 'unit'] |
| #:for a1 in ['f', 'u'] | ||
| #:for k1, t1 in KINDS_TYPES | ||
| module procedure savetxt_${t1[0]}$${k1}$ | ||
| module procedure savetxt_${t1[0]}$${k1}$${a1}$ |
There was a problem hiding this comment.
| module procedure savetxt_${t1[0]}$${k1}$${a1}$ | |
| module procedure savetxt_${t1[0]}$${k1}$${arg1}$ |
There was a problem hiding this comment.
I can use arg1 but I was thinking on only using the first letter to identify the name of the routine, as in the definition (arg1[0]):
#:for arg1 in ['filename', 'unit']
#:for k1, t1 in KINDS_TYPES
subroutine savetxt_${t1[0]}$${k1}$${arg1[0]}$ (${arg1}$ , d, delimiter, fmt, header, footer, comments)
test/io/test_savetxt.f90
Outdated
| d = reshape([1, 2, 3, 4, 5, 6], [3, 2]) | ||
| call savetxt(outpath, d) | ||
| call loadtxt(outpath, d2) | ||
| call savetxt(outpath, d, delimiter=',') |
There was a problem hiding this comment.
Could we keep the initial tests, and add new ones for delimiter=','?
test/io/test_savetxt.f90
Outdated
| e = reshape([1, 2, 3, 4, 5, 6], [2, 3]) | ||
| call savetxt(outpath, e) | ||
| call loadtxt(outpath, d2) | ||
| call savetxt(outpath, e, fmt='(g0.7)', header="Three values per line", footer="Total size = 6", comments='#!') |
There was a problem hiding this comment.
Same comment here: could we keep the initial tests and add new ones for delimiter='``?
There was a problem hiding this comment.
Done, please check if the new tests are ok if you have time
This PR aims to add optional arguments to
savetxt, that behave similar to numpy's savetxt.This is associated with Issue 263 and this discussion thread.
It add the possibility of supplying the unit of an open file instead of a filename (which could be used for
output_unitfor instance)This implementation is quite simple. The main changes are: