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

Mandatorily wrap _read_chunk in a check_chunk_n decorator #758

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions strax/storage/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,13 @@ class StorageBackend:
these have to be hardcoded (or made part of the key).
"""

def __new__(cls, *args, **kwargs):
"""Mandatorily wrap _read_chunk in a check_chunk_n decorator"""
if '_read_chunk' in cls.__dict__:
method = getattr(cls, '_read_chunk')
setattr(cls, '_read_chunk', strax.check_chunk_n(method))
return super(StorageBackend, cls).__new__(cls)

def loader(self,
backend_key,
time_range=None,
Expand Down
1 change: 0 additions & 1 deletion strax/storage/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ def _read_and_format_chunk(self, *args, **kwargs):
chunk.target_size_mb = self.set_chunk_size_mb
return chunk

@strax.check_chunk_n
def _read_chunk(self, dirname, chunk_info, dtype, compressor):
fn = osp.join(dirname, chunk_info['filename'])
return strax.load_file(fn, dtype=dtype, compressor=compressor)
Expand Down
1 change: 0 additions & 1 deletion strax/storage/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def __init__(self, uri: str, database: str, col_name: str):
self._buff_mb = DEFAULT_MONGO_BACKEND_BUFFER_MB
self._buff_nruns = DEFAULT_MONGO_BACKEND_BUFFER_NRUNS

@strax.check_chunk_n
def _read_chunk(self, backend_key, chunk_info, dtype, compressor):
"""See strax.Backend"""
chunk_i = chunk_info["chunk_i"]
Expand Down
2 changes: 0 additions & 2 deletions strax/storage/zipfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ def zip_dir(input_dir, output_zipfile, delete=False):

@export
class ZipFileBackend(strax.StorageBackend):

@strax.check_chunk_n
def _read_chunk(self, zipn_and_dirn, chunk_info, dtype, compressor):
zipn, dirn = zipn_and_dirn
with zipfile.ZipFile(zipn) as zp:
Expand Down