-
Notifications
You must be signed in to change notification settings - Fork 0
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
Added supplement versions table #85
Conversation
cc30d66
to
8c21663
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One actual bug (I think), an API suggestion and ideas for simplifying / reducing the code (less is more!). Mostly looks good though.
agasc/supplement/utils.py
Outdated
versions = _load_or_create(filename, 'versions') | ||
last_updated = _load_or_create(filename, 'last_updated') | ||
|
||
time = CxoTime().iso |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CxoTime.now()
is preferred for being more explicit. The CxoTime()
equivalent is there only for DateTime
compatibility.
Also, I'd suggest setting the time precision to 0 so it just shows to the nearest second (don't need millisec in the date).
time = CxoTime.now()
time.precision = 0
# Then later just use last_updated[key] = time.iso
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check, but I think you can reduce much of the code in the function code to basically:
logger.debug(f'Updating {key} in "versions" and "last_updated" tables')
for key, value in kwargs.items():
versions[key] = [value]
last_updated[key] = [time]
You don't need the 'unknown'
, nor need to pre-declare as columns with a dtype. The key point is that astropy will add in the column or else replace it as the case may be. And I think that the HDF5 writing step will just overwrite whatever is there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to use CxoTime.now
and set precision.
You don't need ... to pre-declare as columns with a dtype.
well, I have gotten upset by astropy changing the types when saving/loading fits files (which might be caused by fits, but still) so I decided to have all table types explicit. Anyway, I changed it according to the suggestion.
agasc/supplement/utils.py
Outdated
versions = get_supplement_table('versions') | ||
|
||
:param filename: pathlib.Path | ||
:param kwargs: dict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this function is always being called (except in testing) with save_version(filename, <table_name>=agasc.__version__)
, maybe just simplify to save_version(filename, table_name)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I thought of that, and I also though of having a default argument. I can remove the argument because it makes it simpler, and one can always add it if you want to use a custom version string.
Are you sure you will not want a custom version string? I changed it according to the suggestion, but one can still undo that commit.
I just added changes according to all these comments. I hope this is it, because I rebase the branch in #86 in my local copy, fixed conflicts, and started doing some refactoring. |
Sure. I had been thinking one table would be fine, but two is also fine. |
if not bad_star_ids: | ||
logger.info('Nothing to update') | ||
return | ||
|
||
if not Path(suppl_file).exists(): | ||
if not suppl_file.exists(): | ||
if not create: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm if we have a create flag, the logger message might not be "warning". But that's a nit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's right. I didn't think of that. I just left the message that was there (which I had made inconsistent because it said "creating new file" and then raised an exception)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!!
@javierggt - I'm leaving to you to merge just to be sure. |
Hey @taldcroft, I had changed the call to Table.write as you suggested, but now I get this error which results from passing a pathlib.Path instead of a string:
When you told me, I tried, it worked and I though "ah, well, maybe I got it wrong"... but no. |
It looks like a bug in astropy, but if you remove the |
I checked and this is still a problem in astropy master. @javierggt - can you file a bug report? |
Description
This PR adds two tables to the supplement:
They have the same structure. Each is a one-row table with string dtype. It is easy to remove the
last_updated
table if you prefer not to have it.I thought of the following options:
utils.get_supplement_table
Testing
Fixes #74