Coverage for /usr/lib/python3/dist-packages/h5py/_debian_h5py_serial/_hl/datatype.py: 50%
22 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1# This file is part of h5py, a Python interface to the HDF5 library.
2#
3# http://www.h5py.org
4#
5# Copyright 2008-2013 Andrew Collette and contributors
6#
7# License: Standard 3-clause BSD; see "license.txt" for full license terms
8# and contributor agreement.
10"""
11 Implements high-level access to committed datatypes in the file.
12"""
14import posixpath as pp
16from ..h5t import TypeID
17from .base import HLObject, with_phil
19class Datatype(HLObject):
21 """
22 Represents an HDF5 named datatype stored in a file.
24 To store a datatype, simply assign it to a name in a group:
26 >>> MyGroup["name"] = numpy.dtype("f")
27 >>> named_type = MyGroup["name"]
28 >>> assert named_type.dtype == numpy.dtype("f")
29 """
31 @property
32 @with_phil
33 def dtype(self):
34 """Numpy dtype equivalent for this datatype"""
35 return self.id.dtype
37 @with_phil
38 def __init__(self, bind):
39 """ Create a new Datatype object by binding to a low-level TypeID.
40 """
41 if not isinstance(bind, TypeID):
42 raise ValueError("%s is not a TypeID" % bind)
43 super().__init__(bind)
45 @with_phil
46 def __repr__(self):
47 if not self.id:
48 return "<Closed HDF5 named type>"
49 if self.name is None:
50 namestr = '("anonymous")'
51 else:
52 name = pp.basename(pp.normpath(self.name))
53 namestr = '"%s"' % (name if name != '' else '/')
54 return '<HDF5 named type %s (dtype %s)>' % \
55 (namestr, self.dtype.str)