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

Fix duplicate appending of scalars in HDF writer and add an overwrite option #1366

Merged
merged 6 commits into from
Dec 4, 2020

Conversation

jaladh-singhal
Copy link
Member

@jaladh-singhal jaladh-singhal commented Dec 4, 2020

When saving a simulation object in HDF using to_hdf() to same file path, the scalars are appended instead of being overwritten causing duplicate values in scalrs series of HDF. This is unlike what happens to other properties like numpy arrays, dataframes, etc. which are always overwritten.

Besides making scalars overwrite (instead of append), this PR makes sure to explicitly prompt users when overwriting a pre-existing HDF file (which earlier used to happen implicitly). For this, a boolean overwrite option is added to to_hdf() which is by default False.

Changes made

  • tardis/io/util.py - fixed scalars appending, added overwrite option & improved related docstrings
  • Several test files using to_hdf() - added overwrite=True since parameterization and session scoped fixtures use same hdf file path and earlier implementation implicitly overwrote the written HDFs.

How Has This Been Tested?

Local tests pass, hopefully Azure pipelines pass too!

@jaladh-singhal jaladh-singhal requested review from wkerzendorf and andrewfullard and removed request for wkerzendorf December 4, 2020 13:33
@codecov
Copy link

codecov bot commented Dec 4, 2020

Codecov Report

Merging #1366 (077cfe7) into master (6564a5e) will decrease coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1366      +/-   ##
==========================================
- Coverage   71.77%   71.72%   -0.06%     
==========================================
  Files          66       66              
  Lines        5077     5071       -6     
==========================================
- Hits         3644     3637       -7     
- Misses       1433     1434       +1     
Impacted Files Coverage Δ
tardis/tardis/io/util.py 71.76% <0.00%> (-1.54%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6564a5e...077cfe7. Read the comment docs.

Returns
-------
overwrite: bool
If the HDF file path already exists, whether overwrite it or not
Copy link
Contributor

Choose a reason for hiding this comment

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

If the HDF file path already exists, whether to overwrite it or not

Comment on lines 224 to 226
`overwrite` option doesn't have any effect when `path_or_buf` is an
HDFStore because it depends on user that in which mode they've opened
it.
Copy link
Contributor

Choose a reason for hiding this comment

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

overwrite option doesn't have an effect when path_or_buf is an HDFStore because the user decides on the mode in which they have opened the HDF (path or HDFStore).

Copy link
Member Author

@jaladh-singhal jaladh-singhal Dec 4, 2020

Choose a reason for hiding this comment

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

Umm...actually I meant, file opening mode ('r', 'w', 'a') - when specifying HDFStore, user has control over the mode in their hands, so overwrite option won't have any effect.

Copy link
Member Author

Choose a reason for hiding this comment

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

Rephrased it - let me know if it still needs changes!

Copy link
Contributor

@andrewfullard andrewfullard left a comment

Choose a reason for hiding this comment

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

Just a couple of minor documentation adjustments. Otherwise looks good.

@andrewfullard andrewfullard merged commit 1249c4e into tardis-sn:master Dec 4, 2020
atharva-2001 pushed a commit to atharva-2001/tardis that referenced this pull request Oct 1, 2021
Fix duplicate appending of scalars in HDF writer and add an overwrite option
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