Skip to content

Commit

Permalink
module query funcs can guess the filename
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasprobst committed Nov 7, 2023
1 parent 79a8a6d commit 7776fbb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
20 changes: 16 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,38 @@

Log of changes in the versions

## v0.12.2

- bugfix requirements
- add `$exist` `find()`-methods inside of HDF files
- bugfix 0D time data as dimension
- module query functions (`find`, ...) can guess the filename from objects that have with `hasattr(hdf_filename, 'hdf_filename')`

## v0.12.1

- bugfix in zenodo search (did Zenodo change their API?)

## v0.12.0

- 0D data is written to MongoDB
- new utils like computing filesize
- new utils like computing filesize
- update to new zenodo_search package due to change in backend at Zenodo.org
- `find`, `find_one` and `distinct` can be called on HDF files
- small bugfixes

## v0.11.1

- bugfix standard attribute validation
- bugfix in `EngMeta.ipynb`

## v0.11.0

- working with time data is now possible:
- time data can be created using the high-level method `create_time_dataset`
- slicing the above "time datasets" will return xarray data
- See `docs/wrapper/Misc.ipynb`
- time data can be created using the high-level method `create_time_dataset`
- slicing the above "time datasets" will return xarray data
- See `docs/wrapper/Misc.ipynb`
- fixed issue with user-defined & nested standard attributes

## v0.10.0

- Initial version, published on `pypi`
22 changes: 19 additions & 3 deletions h5rdmtoolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""h5rdtoolbox repository"""
import atexit
import pathlib
import shutil
from typing import Union, Callable

# noinspection PyUnresolvedReferences
import pint_xarray
import shutil
import xarray as xr
from typing import Union, Callable

from h5rdmtoolbox._cfg import set_config, get_config, get_ureg

Expand Down Expand Up @@ -68,16 +67,33 @@ def __new__(cls, path, rec=False, **kwargs):
return database.File(path, **kwargs)


def guess_filename(func):
"""wrapper to guess the filename from the first argument"""

def wrapper(hdf_filename, *args, **kwargs):
if not isinstance(hdf_filename, (str, pathlib.Path)):
if hasattr(hdf_filename, 'hdf_filename'):
hdf_filename = hdf_filename.hdf_filename
else:
raise TypeError(f'Expected str or pathlib.Path, got {type(hdf_filename)}')
return func(hdf_filename, *args, **kwargs)

return wrapper


@guess_filename
def find(hdf_filename, *args, **kwargs):
"""Opens file with `FileDB` and calls `find()` on the root group"""
return FileDB(hdf_filename).find(*args, **kwargs)


@guess_filename
def find_one(hdf_filename, *args, **kwargs):
"""Opens file with `FileDB` and calls `find_one()` on the root group"""
return FileDB(hdf_filename).find_one(*args, **kwargs)


@guess_filename
def distinct(hdf_filename, key, objfilter=None):
"""Opens file and calls `distinct()` on the root group"""
with File(hdf_filename) as h5:
Expand Down

0 comments on commit 7776fbb

Please sign in to comment.