Skip to content
Prev Previous commit
Next Next commit
ENH: adds Docstring to the function
  • Loading branch information
GMinoruy authored and Gui-FernandesBR committed Dec 9, 2025
commit d0cc223ee8fe31f5f1f4e31a2d1cd45ec8702a27
14 changes: 14 additions & 0 deletions rocketpy/simulation/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,20 @@ def __evaluate_flight_outputs(self, flight, sim_idx):
)

def export_results(self, output_filename, output_format):
"""Converts the default Monte Carlo .txt output to .cvs or .json file
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Typo in docstring: ".cvs" should be ".csv"

Suggested change
"""Converts the default Monte Carlo .txt output to .cvs or .json file
"""Converts the default Monte Carlo .txt output to .csv or .json file

Copilot uses AI. Check for mistakes.
depending on the user's choice

Parameters
----------
output_filename : str
Name of the file in which the converted data will be saved
output_format : str
Format of the output file

Returns
-------
None
Comment on lines +593 to +605
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The docstring is missing important details. It should:

  1. Specify that output_filename can be a string or Path object
  2. Document the valid values for output_format ("csv" or "json")
  3. Explain what happens if the output file already exists (will it be overwritten?)
  4. Mention that the method reads from self.filename.outputs.txt
  5. Follow NumPy docstring format with a proper description section before Parameters

Example improvement:

\"\"\"Export Monte Carlo simulation results to CSV or JSON format.

This method reads simulation output data from the `.outputs.txt` file
and converts it to either CSV or JSON format based on user selection.

Parameters
----------
output_filename : str or Path
    Path and name of the output file (without extension). The appropriate
    extension (.csv or .json) will be added automatically.
output_format : str
    Format of the output file. Must be either "csv" or "json" (case-insensitive).

Returns
-------
None

Raises
------
FileNotFoundError
    If the `.outputs.txt` file does not exist.
ValueError
    If `output_format` is not "csv" or "json".
\"\"\"
Suggested change
"""Converts the default Monte Carlo .txt output to .cvs or .json file
depending on the user's choice
Parameters
----------
output_filename : str
Name of the file in which the converted data will be saved
output_format : str
Format of the output file
Returns
-------
None
"""Export Monte Carlo simulation results to CSV or JSON format.
This method reads simulation output data from the `.outputs.txt` file
(specifically, from `self.filename.outputs.txt`) and converts it to either
CSV or JSON format based on user selection. The output file will be
overwritten if it already exists.
Parameters
----------
output_filename : str or Path
Path and name of the output file (without extension). The appropriate
extension (.csv or .json) will be added automatically.
output_format : str
Format of the output file. Must be either "csv" or "json"
(case-insensitive).
Returns
-------
None
Raises
------
FileNotFoundError
If the `.outputs.txt` file does not exist.
ValueError
If `output_format` is not "csv" or "json".
Examples
--------
>>> mc.export_results("results", "csv")
>>> mc.export_results(Path("results_folder/results"), "json")

Copilot uses AI. Check for mistakes.
"""
txt_data = []
with open(f"{self.filename}.outputs.txt", "r", encoding="utf-8") as f:
for line in f:
Expand Down