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

Refactor of LH5 I/O routines, deprecation of existing methods #24

Merged
merged 13 commits into from
Nov 24, 2023

Conversation

MoritzNeuberger
Copy link
Contributor

#3
Second attempt to implement the refactoring of lh5 related classes and functions into a separate folder.
This refactoring also requires changes to the other relevant repositories (pygama, dspeed, legend-daq2lh5) as the include paths have changed. They will be included in pull requests for each package individually.

Some notes:

  • ls and show are still in the store.py file. They cannot be moved to utils.py as they reference the LH5Store object, which would result in a circular import. Should we try to move them to a separate file?
  • Is it okay to call the utility files both utils.py at different levels? I am not an expert enough to know if this could cause problems with the import.

@codecov
Copy link

codecov bot commented Oct 30, 2023

Codecov Report

Attention: 152 lines in your changes are missing coverage. Please review.

Comparison is base (56298ed) 75.49% compared to head (ff8d627) 74.87%.

Files Patch % Lines
src/lgdo/lh5/store.py 84.50% 88 Missing ⚠️
src/lgdo/lh5/iterator.py 80.25% 31 Missing ⚠️
src/lgdo/lgdo_utils.py 0.00% 14 Missing ⚠️
src/lgdo/lh5_store.py 62.16% 14 Missing ⚠️
src/lgdo/lh5/utils.py 91.42% 3 Missing ⚠️
src/lgdo/utils.py 93.10% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #24      +/-   ##
==========================================
- Coverage   75.49%   74.87%   -0.62%     
==========================================
  Files          22       27       +5     
  Lines        2126     2209      +83     
==========================================
+ Hits         1605     1654      +49     
- Misses        521      555      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MoritzNeuberger MoritzNeuberger changed the title Issue 3 lh5 store refactor lh5_store.py refactor (2nd attempt) Oct 30, 2023
@MoritzNeuberger
Copy link
Contributor Author

Should I wait until this PR is reviewed before making the PR in the other repositories?

@gipert
Copy link
Member

gipert commented Oct 30, 2023

First of all: thanks a lot @MoritzNeuberger for taking care of this!

ls and show are still in the store.py file. They cannot be moved to utils.py as they reference the LH5Store object, which would result in a circular import. Should we try to move them to a separate file?

I would say so, yes.

Is it okay to call the utility files both utils.py at different levels? I am not an expert enough to know if this could cause problems with the import.

It's perfectly ok, in my opinion, since the scope is made clear by the subpackage name: lgdo.utils vs lgdo.lh5.utils.

Should we also:

  • rename LH5Iterator/LH5Store to just Iterator/Store?
  • Since this will break user code, keep it backward compatible for a while? Maybe just like we did in pygama?

Should I wait until this PR is reviewed before making the PR in the other repositories?

Yes, let's try to get this merged first.

@gipert gipert requested review from gipert and jasondet October 30, 2023 13:00
@gipert gipert linked an issue Oct 30, 2023 that may be closed by this pull request
@gipert gipert added this to the v2 milestone Oct 30, 2023
@gipert gipert added the lh5 HDF5 I/O label Nov 3, 2023
Copy link
Member

@gipert gipert left a comment

Choose a reason for hiding this comment

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

For discussion: do we really want to drop the LH5 prefix in LH5Store and LH5Iterator? I like the lh5.Store and lh5.Iterator syntax more, but I wonder if the LH5 prefix could still be useful, if the names are individually imported.

Moritz: have you checked if there is any broken Sphinx reference left in files not affected by this PR? I guess it would be useful to turn on the Sphinx option to error/warn if cross-references are broken.

LGDO = Union[Array, Scalar, Struct, VectorOfVectors]


class LH5Iterator(Iterator):
Copy link
Member

Choose a reason for hiding this comment

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

This should be renamed to Iterator in my opinion.

@@ -101,7 +101,7 @@
"id": "ef09f43c",
"metadata": {},
"source": [
"The group contains several LGDOs. Let's read them in memory. We start by initializing an `LH5Store` [[docs]](https://legend-pydataobj.readthedocs.io/en/stable/api/lgdo.html#lgdo.lh5_store.LH5Store) object:"
"The group contains several LGDOs. Let's read them in memory. We start by initializing an `Store` [[docs]](https://legend-pydataobj.readthedocs.io/en/stable/api/lgdo.html#lgdo.lh5_store.Store) object:"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"The group contains several LGDOs. Let's read them in memory. We start by initializing an `Store` [[docs]](https://legend-pydataobj.readthedocs.io/en/stable/api/lgdo.html#lgdo.lh5_store.Store) object:"
"The group contains several LGDOs. Let's read them in memory. We start by initializing an `Store` [[docs]](https://legend-pydataobj.readthedocs.io/en/stable/api/lgdo.html#lgdo.lh5.Store) object:"

All these links need to be fixed in the documentation...

Comment on lines 70 to 71
"Iterator",
"Store",
Copy link
Member

Choose a reason for hiding this comment

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

I guess we should remove these imports from the lh5 submodule, especially if we are dropping the LH5 prefix. The user should import lgdo.lh5.Store, and not lgdo.Store. But see my comment about this prefix in the review summary.

src/lgdo/cli.py Outdated
@@ -5,11 +5,11 @@

import lgdo
import lgdo.logging
from lgdo import show
from lgdo.lh5.store import show
Copy link
Member

Choose a reason for hiding this comment

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

Uhm I forgot to use relative imports in this file. Could you just import from . instead of lgdo?

obj.resize(new_size=size)
return obj

def read_object(
Copy link
Member

Choose a reason for hiding this comment

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

I propose to rename read_object() and write_object() to just read() and write(). "object" sounds redundant to me.

@MoritzNeuberger
Copy link
Contributor Author

I realized that I haven't made the change of read_object and write_object to read and write backwards compatible. Will do so asap.

@jasondet
Copy link
Contributor

It looks like lgdo_utils.get_element_type and lgdo_utils.copy also both need bw compatibility calls?

Yeah it looks like you just need to go through each def and make sure there is a deprication warning and appropriate call-through. Thank you Moritz!

Copy link
Contributor

@jasondet jasondet left a comment

Choose a reason for hiding this comment

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

just need to go through each def and make sure there is a deprication warning and appropriate call-through

@gipert
Copy link
Member

gipert commented Nov 21, 2023

lgdo_utils.copy will be deprecated once #30 is merged. I think it's also being barely used atm, @MoritzNeuberger you can just go ahead and remove it.

@gipert gipert changed the title lh5_store.py refactor (2nd attempt) Refactor of LH5 I/O routines, deprecation of existing methods Nov 23, 2023
@MoritzNeuberger
Copy link
Contributor Author

Hmm, seems like it didn't work with that approach. What I did was delete store.py while keeping the source in a separate file. Then I used git mv to move the lh5_store.py file into lh5 and committed. Then I changed the filename and committed again. Finally, I created a new lh5_store.py and filled both files with the appropriate content. When I run git log --follow store.py I get the full history, but I do not know how to keep the full history as it is not fully displayed on github.

@MoritzNeuberger MoritzNeuberger force-pushed the issue_3_lh5_store_refactor branch from 227324d to 063fdb9 Compare November 24, 2023 10:41
docs/source/extensions/numbadoc.py Outdated Show resolved Hide resolved
docs/source/notebooks/LH5Files.ipynb Outdated Show resolved Hide resolved
src/lgdo/compression/radware.py Outdated Show resolved Hide resolved
Co-authored-by: Luigi Pertoldi <gipert@pm.me>
@gipert
Copy link
Member

gipert commented Nov 24, 2023

This looks good to me, I will merge.

@gipert gipert merged commit 772fe17 into legend-exp:main Nov 24, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lh5 HDF5 I/O
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lh5_store.py refactor
3 participants