Skip to content

Commit

Permalink
rename register_special_dataset to register_accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasprobst committed May 1, 2024
1 parent 68833ee commit a1de8f3
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
3 changes: 2 additions & 1 deletion h5rdmtoolbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
from .wrapper import jsonld
from .wrapper.lazy import lazy
from .wrapper.h5attr import Attribute
from .wrapper.accessor import register_special_dataset
# from h5rdmtoolbox.wrapper.accessor import register_accessor
import json
from .wrapper.accessor import register_accessor

name = 'h5rdmtoolbox'
__this_dir__ = pathlib.Path(__file__).parent
Expand Down
6 changes: 3 additions & 3 deletions h5rdmtoolbox/extensions/magnitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Dict, Optional

from h5rdmtoolbox.protocols import H5TbxDataset
from h5rdmtoolbox.wrapper.accessor import Accessor, register_special_dataset
from h5rdmtoolbox.wrapper.accessor import Accessor, register_accessor


class MagnitudeInterface:
Expand Down Expand Up @@ -48,8 +48,8 @@ def sel(self, method=None, **coords):
)


@register_special_dataset("Magnitude", "Group")
@register_special_dataset("Magnitude", "File")
@register_accessor("Magnitude", "Group")
@register_accessor("Magnitude", "File")
class Magnitude(Accessor):
def __call__(self, *datasets, name: Optional[str] = None, keep_attrs: bool = False) -> MagnitudeInterface:
if len(datasets) < 2:
Expand Down
4 changes: 2 additions & 2 deletions h5rdmtoolbox/extensions/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from h5rdmtoolbox import get_ureg
from h5rdmtoolbox.protocols import H5TbxDataset
from h5rdmtoolbox.wrapper.accessor import Accessor, register_special_dataset
from h5rdmtoolbox.wrapper.accessor import Accessor, register_accessor

NORM_DELIMITER = '/'

Expand Down Expand Up @@ -90,7 +90,7 @@ def __call__(self,
return self._ni


@register_special_dataset("normalize", "Dataset")
@register_accessor("normalize", "Dataset")
class ToUnitsAccessor(Accessor):
"""Accessor to await selected data to be converted to a new units"""

Expand Down
4 changes: 2 additions & 2 deletions h5rdmtoolbox/extensions/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from h5rdmtoolbox import get_ureg
from h5rdmtoolbox.protocols import H5TbxDataset
from h5rdmtoolbox.wrapper.accessor import Accessor, register_special_dataset
from h5rdmtoolbox.wrapper.accessor import Accessor, register_accessor


class ToUnitsInterface:
Expand Down Expand Up @@ -37,7 +37,7 @@ def __getitem__(self, *args, **kwargs):
return self._convert_units(self.dataset.__getitem__(*args, **kwargs))


@register_special_dataset("to_units", "Dataset")
@register_accessor("to_units", "Dataset")
class ToUnitsAccessor(Accessor):
"""Accessor to await selected data to be converted to a new units"""

Expand Down
7 changes: 3 additions & 4 deletions h5rdmtoolbox/extensions/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from typing import Dict, Optional

from h5rdmtoolbox.protocols import H5TbxDataset
from h5rdmtoolbox.wrapper.accessor import Accessor, register_special_dataset
from . import magnitude # automatically make magnitude available
from h5rdmtoolbox.wrapper.accessor import Accessor, register_accessor


class VectorInterface:
Expand All @@ -23,8 +22,8 @@ def __getitem__(self, item) -> xr.Dataset:
combine_attrs=self.combine_attrs)


@register_special_dataset("Vector", "Group")
@register_special_dataset("Vector", "File")
@register_accessor("Vector", "Group")
@register_accessor("Vector", "File")
class Vector(Accessor):
def __call__(self,
*args,
Expand Down
8 changes: 4 additions & 4 deletions h5rdmtoolbox/wrapper/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from typing import Union, Type

from ..protocols import H5TbxHLObject
from h5rdmtoolbox.protocols import H5TbxHLObject

logger = logging.getLogger('h5rdmtoolbox')

Expand Down Expand Up @@ -50,7 +50,7 @@ def __get__(self, obj, cls):
PROPERTY_ACCESSOR_NAMES = []


def _register_special_dataset(name, cls, special_dataset, overwrite):
def _register_accessor(name, cls, special_dataset, overwrite):
if hasattr(cls, name):
if not overwrite:
raise RuntimeError(f'Cannot register the accessor {special_dataset!r} under name {name!r} '
Expand All @@ -60,7 +60,7 @@ def _register_special_dataset(name, cls, special_dataset, overwrite):
return special_dataset


def register_special_dataset(name, cls: Union[str, Type[H5TbxHLObject]], overwrite=False):
def register_accessor(name, cls: Union[str, Type[H5TbxHLObject]], overwrite=False):
"""registers a special dataset to a wrapper class"""

if isinstance(cls, str):
Expand All @@ -78,7 +78,7 @@ def register_special_dataset(name, cls: Union[str, Type[H5TbxHLObject]], overwri

def decorator(accessor):
"""decorator"""
return _register_special_dataset(name, cls, accessor, overwrite)
return _register_accessor(name, cls, accessor, overwrite)

return decorator

Expand Down
2 changes: 1 addition & 1 deletion h5rdmtoolbox/wrapper/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def _add_hdf_node(name, obj, ctx) -> Dict:
try:
attr_literal = rdflib.Literal(json.dumps(av))
except TypeError as e:
warnings.warn(f'Could not serialize {av} to JSON. Will apply str(). Error: {e}')
logger.debug(f'Could not serialize {av} to JSON. Will apply str(). Error: {e}')
attr_literal = rdflib.Literal(str(av))

if attr_literal:
Expand Down

0 comments on commit a1de8f3

Please sign in to comment.