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

Upgrade compare-metadata function #778

Merged
merged 21 commits into from
Dec 19, 2023
Merged

Conversation

KaraMelih
Copy link
Contributor

What is the problem / what does the code in this PR do

The previous version of the st.compare_metadata() was accepting one runid+target pair and one already existing metadata JSON file as was pointed here: #770 by @WenzDaniel
This upgrade allows for two sets of //either// runid+target pairs or existing metadata in the form of a path to the JSON file or already loaded dictionary, to do the comparison. In case the data is not loaded anywhere (e.g. peak positions) instead of doing a full metadata comparison, it just compares the lineages.
It also allows to return of extracted metadata and lineage of both requested data for convenience, if return_results=True is passed.

Can you briefly describe how it works?

You get your favorite context, and call the attribute;

context.compare_metadata(  ("053877", "peak_basics"), ("053877", "peak_positions"))
context.compare_metadata(  ("053875", "peak_basics"), ("053877", "peak_basics"))
context.compare_metadata(  ("053877", "peak_basics"),  "./my_path_to/JSONfile.json")
first_metadata = context.get_metadata(run_id, "events")
context.compare_metadata(  ("053877", "peak_basics"), first_metadata)
context.compare_metadata(  ("053877", "records"), ("053899", "records") )

Can you give a minimal working example (or illustrate with a figure)?

import cutax
st = cutax.contexts.xenonnt_online(_rucio_local_path='/project/lgrandi/rucio', include_rucio_local=True, include_rucio_remote=True)
st.compare_metadata(  ("053875", "peak_basics"), ("053877", "peak_basics") )

Please include the following if applicable:

  • Update the docstring(s)
  • Update the documentation
  • Tests to check the (new) code is working as desired.
  • Does it solve one of the open issues on github? Solves Extend compare_metadata #770

Please make sure that all automated tests have passed before asking for a review (you can save the PR as a draft otherwise).

@coveralls
Copy link

coveralls commented Nov 27, 2023

Coverage Status

coverage: 91.35% (-0.2%) from 91.586%
when pulling 816f26d on KaraMelih:master
into 70f69c8 on AxFoundation:master.

@KaraMelih
Copy link
Contributor Author

@WenzDaniel could you help me understand this failing test?
https://www.codefactor.io/repository/github/axfoundation/strax/pull/778
it refers to two definitions that do not come from this PR but already existing

@WenzDaniel
Copy link
Collaborator

Hej @KaraMelih thank you very much for the update I think your PR goes in a very different direction than I had in my mind. The issue we had is, that if you compare the metadata of the currently used context with some old data stored somewhere that you can only perform this comparison if the metadata of your currently used context is stored somewhere. However, I think most of the time the use case is the other way around: I have a context and I cannot load any data anymore and I would like to understand why my context is different than the one used for the stored data. So only adding a simple try/except would have been already sufficient. Sorry for all the extra work. I will look into your PR now.

WenzDaniel
WenzDaniel previously approved these changes Dec 14, 2023
Copy link
Collaborator

@WenzDaniel WenzDaniel left a comment

Choose a reason for hiding this comment

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

Thanks @KaraMelih works like a charm. Maybe you can add the doc-string a little and then we can merge.

@@ -1844,30 +1844,89 @@ def get_meta(self, run_id, target) -> dict:

get_metadata = get_meta

def compare_metadata(self, run_id, target, old_metadata):
def compare_metadata(self, data1, data2, return_results=False):
"""Compare the metadata between two strax data.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add to the doc string which explains the pintout of the comparison. I was a little confused which direction things are compared is red the first and green the second file?

:param target: data type to get
:param old_metadata: path to metadata to compare, or a dictionary, or a tuple with another
run_id, target to compare against the metadata of the first id-target pair
:param data1, data2: either a list (tuple) of runid + target pair, or path to metadata to
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add into your doc string the examples you provided here in github. Then I think it becomes more clea, like:

"""
doc-string so far

    Examples:
    example code 1
    example code 2
"""

metadata["lineage"] if _is_stored else self.key_for(run_id, target).lineage
)
_lineage_hash = str(self.key_for(run_id, target))
print(_lineage_hash)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove print statement?

Comment on lines +1884 to +1885
_is_stored = self.is_stored(run_id, target)
metadata = self.get_metadata(run_id, target) if _is_stored else None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here you could have used a

try: 
   self.get_metadata(...)
except strax,DataNotStored:
   ....

(or what ever raise we are returning in case it is not stored.) Just as information for the future

@WenzDaniel
Copy link
Collaborator

Btw you can ignore the failing code factor.

@WenzDaniel WenzDaniel merged commit f7e0dd3 into AxFoundation:master Dec 19, 2023
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.

None yet

4 participants