From 9d31ecf3856ccba10c6dcef977d8930c9bd1c3cb Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Tue, 3 Sep 2024 17:02:50 -0700 Subject: [PATCH] bump version, docs, nocover error checking --- docs/changelog.md | 5 +++++ pyproject.toml | 2 +- src/numpydantic/interface/hdf5.py | 17 ++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 29c0fe8..c739535 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,11 @@ ### 1.5.* +#### 1.5.2 - 24-09-03 - `datetime` support for HDF5 + +- [#15](https://github.com/p2p-ld/numpydantic/pull/15): Datetimes are supported as + dtype annotations for HDF5 arrays when encoded as `S32` isoformatted byte strings + #### 1.5.1 - 24-09-03 - Fix revalidation with proxy classes Bugfix: diff --git a/pyproject.toml b/pyproject.toml index 9b9b15e..7c8b8ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "numpydantic" -version = "1.5.1" +version = "1.5.2" description = "Type and shape validation and serialization for arbitrary array types in pydantic models" authors = [ {name = "sneakers-the-rat", email = "sneakers-the-rat@protonmail.com"}, diff --git a/src/numpydantic/interface/hdf5.py b/src/numpydantic/interface/hdf5.py index 7861f3c..4fc548d 100644 --- a/src/numpydantic/interface/hdf5.py +++ b/src/numpydantic/interface/hdf5.py @@ -22,6 +22,21 @@ Interfaces for HDF5 Datasets To have direct access to the hdf5 dataset, use the :meth:`.H5Proxy.open` method. +Datetimes +--------- + +Datetimes are supported as a dtype annotation, but currently they must be stored +as ``S32`` isoformatted byte strings (timezones optional) like: + +.. code-block:: python + + import h5py + from datetime import datetime + import numpy as np + data = np.array([datetime.now().isoformat().encode('utf-8')], dtype="S32") + h5f = h5py.File('test.hdf5', 'w') + h5f.create_dataset('data', data=data) + """ import sys @@ -311,7 +326,7 @@ class H5Interface(Interface): return np.datetime64 else: return str - except (AttributeError, ValueError, TypeError): + except (AttributeError, ValueError, TypeError): # pragma: no cover return str else: return array.dtype