Skip to content

Commit

Permalink
MNT: pin hsds to 0.8.0 (latest known working version), update h5pyd t…
Browse files Browse the repository at this point in the history
…ests, use h5py/h5pyd functions where appropriate
  • Loading branch information
kmuehlbauer committed Jan 16, 2024
1 parent 875e1c9 commit 48b0223
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 134 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9"]
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
- name: Install micromamba
Expand All @@ -94,7 +94,7 @@ jobs:
- name: Install h5netcdf
run: |
python -m pip install . --no-deps --ignore-installed --no-cache-dir -vvv
python -m pip install git+https://github.com/HDFGroup/hsds.git
python -m pip install git+https://github.com/HDFGroup/hsds.git@0.8.0
python -m pip install git+https://github.com/HDFGroup/h5pyd.git
- name: Test with pytest
run: |
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Development Version:

- Add enum type.
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_
- Update h5pyd testing.
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_

Version 1.3.0 (November 7th, 2023):

Expand Down
28 changes: 16 additions & 12 deletions h5netcdf/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,13 @@ def __len__(self):
@property
def datatype(self):
"""Return numpy dtype or user defined type."""
if h5py.check_enum_dtype(self.dtype) is not None:
if (enum_dict := self._root._h5py.check_enum_dtype(self.dtype)) is not None:
for tid in self._parent._all_enumtypes.values():
if self._h5ds.id.get_type().equal(tid._h5ds.id):
if self._root._h5py == h5py:
found = self._h5ds.id.get_type().equal(tid._h5ds.id)
else:
found = tid.enum_dict == enum_dict
if found:
return tid
return self.dtype

Expand Down Expand Up @@ -393,13 +397,13 @@ def __setitem__(self, key, value):
from .legacyapi import Dataset

# check if provided values match enumtype values
if isinstance(self.datatype, EnumType):
mask = np.isin(value, list(self.datatype.enum_dict.values()))
if enum_dict := self._root._h5py.check_enum_dtype(self.dtype):
mask = np.isin(value, list(enum_dict.values()))
wrong = set(np.asanyarray(value)[~mask])
if not mask.all():
raise ValueError(
f"Trying to assign illegal value(s) {wrong!r} to Enum variable {self.name!r}."
f" Valid values are {dict(self.datatype.enum_dict)!r}."
f" Valid values are {dict(enum_dict)!r}."
)

if isinstance(self._parent._root, Dataset):
Expand Down Expand Up @@ -564,9 +568,9 @@ def __init__(self, parent, name):
# instance
self._groups.add(k)
# todo: add other user types here
elif isinstance(v, self._root._h5py.Datatype) and h5py.check_enum_dtype(
v.dtype
):
elif isinstance(
v, self._root._h5py.Datatype
) and self._root._h5py.check_enum_dtype(v.dtype):
self._enumtypes.add(k)
else:
if v.attrs.get("CLASS") == b"DIMENSION_SCALE":
Expand Down Expand Up @@ -1056,7 +1060,7 @@ def create_enumtype(self, datatype, datatype_name, enum_dict):
enum_dict: dict
A Python dictionary containing the Enum field/value pairs.
"""
et = h5py.enum_dtype(enum_dict, basetype=datatype)
et = self._root._h5py.enum_dtype(enum_dict, basetype=datatype)
self._h5group[datatype_name] = et
# create enumtype class instance
enumtype = self._enumtype_cls(self, datatype_name)
Expand Down Expand Up @@ -1229,9 +1233,9 @@ def _check_valid_netcdf_dtype(self, dtype):
description = "boolean"
elif dtype == complex:
description = "complex"
elif h5py.check_dtype(ref=dtype) is not None:
elif self._h5py.check_dtype(ref=dtype) is not None:
description = "reference"
elif h5py.check_dtype(vlen=dtype) not in {None, str, bytes}:
elif self._h5py.check_dtype(vlen=dtype) not in {None, str, bytes}:
description = "non-string variable length"
else:
description = None
Expand Down Expand Up @@ -1270,7 +1274,7 @@ def flush(self):
)
self.attrs._h5attrs["_NCProperties"] = np.array(
_NC_PROPERTIES,
dtype=h5py.string_dtype(
dtype=self._h5py.string_dtype(
encoding="ascii", length=len(_NC_PROPERTIES)
),
)
Expand Down
3 changes: 1 addition & 2 deletions h5netcdf/dimensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from collections import OrderedDict
from collections.abc import MutableMapping

import h5py
import numpy as np


Expand Down Expand Up @@ -138,7 +137,7 @@ def _h5ds(self):

@property
def _isscale(self):
return h5py.h5ds.is_scale(self._h5ds.id)
return self._root._h5py.h5ds.is_scale(self._h5ds.id)

@property
def _dimid(self):
Expand Down
Loading

0 comments on commit 48b0223

Please sign in to comment.