Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@wasimxyz
Copy link
Contributor

@wasimxyz wasimxyz commented Dec 20, 2024

Summary

No file is generated when save_spectra is called and the spectra parameter is an empty list, which can be unexpected behavior. This PR addresses that by generating an empty file and logging a warning. Completes #586.

Changes

In save_spectra:

if not isinstance(spectra, list):
    spectra = [spectra]

if len(spectra) == 0:
    logger.warning("No spectra to save. File will be empty.")
    open(file, "w").close()
    return

The diff is large because I reformatted the files in the exporting module (out of habit). I can revert these changes if desired.

Testing

Ran the following code and confirmed that an empty file was created. Unit tests are passing on my machine.

import matchms
spectra = []
matchms.exporting.save_spectra(
    spectra, file="spectra.json", export_style="json"
)

@julianpollmann julianpollmann self-requested a review February 10, 2025 15:54
@wasimxyz
Copy link
Contributor Author

wasimxyz commented Mar 3, 2025

@julianpollmann Hi, just bumping this PR to see if there's any update. 🙂

@julianpollmann julianpollmann merged commit 2cf4c09 into matchms:master Mar 11, 2025
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.

2 participants