Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose configuring input CSV file formatting options #53

Merged
merged 6 commits into from
Jan 22, 2025

Conversation

sstroemer
Copy link
Member

As discussed internally on 17.01.2025.

The most common two use cases might be:

# "German" with comments
config:
  files:
    _csv_config:
      comment: "#"
      delim: ";"
      decimal: ","
# "English" without comments
config:
  files:
    _csv_config:
      delim: ","
      decimal: "."

Auto-summary below.


This pull request introduces several changes related to CSV file handling and configuration in the project. The key updates include the addition of a new example configuration file, modifications to the file parsing logic, and updates to the CSV reading function to support custom delimiters and decimal separators.

CSV Configuration Enhancements:

  • Added a new example configuration file 49_csv_formats.iesopt.yaml to demonstrate different CSV formats and configurations.
  • Updated _prepare_config_files! function in src/config/sections/files.jl to handle _csv_config settings and issue warnings for file names starting with an underscore.

File Parsing and Preloading:

  • Modified _parse_model! and _parse_global_addons functions in src/parser.jl to exclude files starting with an underscore from preloading and to streamline file parsing logic. [1] [2]

CSV Reading Function:

  • Enhanced _getcsv function in src/utils/general.jl to utilize the _csv_config settings for comment characters, delimiters, and decimal separators. Added error logging for CSV reading issues. [1] [2]

Testing:

  • Added new tests in test/src/examples.jl to validate the new CSV format configurations and ensure proper functionality.

@sstroemer
Copy link
Member Author

This is the first time we add an "experimental" feature to the YAML spec. This now starts with "_" (which we could re-use in the future), and we settled on potentially changing/discontinuing such "private" features of the YAML without the need for a major version bump.

@sstroemer sstroemer added the enhancement New feature or request label Jan 18, 2025
Copy link

codecov bot commented Jan 18, 2025

Codecov Report

Attention: Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 50.20%. Comparing base (36ac0da) to head (39b3285).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/config/sections/files.jl 87.50% 1 Missing ⚠️
src/utils/general.jl 92.85% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main      #53      +/-   ##
==========================================
+ Coverage   49.57%   50.20%   +0.63%     
==========================================
  Files         109      109              
  Lines        4303     4322      +19     
==========================================
+ Hits         2133     2170      +37     
+ Misses       2170     2152      -18     
Files with missing lines Coverage Δ
src/parser.jl 81.57% <100.00%> (ø)
src/config/sections/files.jl 90.90% <87.50%> (-9.10%) ⬇️
src/utils/general.jl 53.95% <92.85%> (+2.22%) ⬆️

... and 1 file with indirect coverage changes

@sstroemer
Copy link
Member Author

This was initially triggered by ait-energy/iesopt#27

@sstroemer
Copy link
Member Author

We need to create a new iesopt release, so that this feature can be used without a custom .env file for Python users, refer to ait-energy/iesopt#64.

Documentation is already available!

Copy link
Collaborator

@daschw daschw left a comment

Choose a reason for hiding this comment

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

Looks good! :)

@sstroemer sstroemer merged commit 57b3d60 into ait-energy:main Jan 22, 2025
6 of 8 checks passed
@sstroemer sstroemer deleted the config-csv-file-format branch January 22, 2025 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants