Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tables/unimplemented.py: 47%

49 statements  

« prev     ^ index     » next       coverage.py v7.2.5, created at 2023-05-10 06:15 +0000

1"""Here is defined the UnImplemented class.""" 

2 

3import warnings 

4 

5from . import hdf5extension 

6from .utils import SizeType 

7from .node import Node 

8from .leaf import Leaf 

9 

10 

11class UnImplemented(hdf5extension.UnImplemented, Leaf): 

12 """This class represents datasets not supported by PyTables in an HDF5 

13 file. 

14 

15 When reading a generic HDF5 file (i.e. one that has not been created with 

16 PyTables, but with some other HDF5 library based tool), chances are that 

17 the specific combination of datatypes or dataspaces in some dataset might 

18 not be supported by PyTables yet. In such a case, this dataset will be 

19 mapped into an UnImplemented instance and the user will still be able to 

20 access the complete object tree of the generic HDF5 file. The user will 

21 also be able to *read and write the attributes* of the dataset, *access 

22 some of its metadata*, and perform *certain hierarchy manipulation 

23 operations* like deleting or moving (but not copying) the node. Of course, 

24 the user will not be able to read the actual data on it. 

25 

26 This is an elegant way to allow users to work with generic HDF5 files 

27 despite the fact that some of its datasets are not supported by 

28 PyTables. However, if you are really interested in having full access to an 

29 unimplemented dataset, please get in contact with the developer team. 

30 

31 This class does not have any public instance variables or methods, except 

32 those inherited from the Leaf class (see :ref:`LeafClassDescr`). 

33 

34 """ 

35 

36 # Class identifier. 

37 _c_classid = 'UNIMPLEMENTED' 

38 

39 def __init__(self, parentnode, name): 

40 """Create the `UnImplemented` instance.""" 

41 

42 # UnImplemented objects always come from opening an existing node 

43 # (they can not be created). 

44 self._v_new = False 

45 """Is this the first time the node has been created?""" 

46 self.nrows = SizeType(0) 

47 """The length of the first dimension of the data.""" 

48 self.shape = (SizeType(0),) 

49 """The shape of the stored data.""" 

50 self.byteorder = None 

51 """The endianness of data in memory ('big', 'little' or 

52 'irrelevant').""" 

53 

54 super().__init__(parentnode, name) 

55 

56 def _g_open(self): 

57 (self.shape, self.byteorder, object_id) = self._open_unimplemented() 

58 try: 

59 self.nrows = SizeType(self.shape[0]) 

60 except IndexError: 

61 self.nrows = SizeType(0) 

62 return object_id 

63 

64 def _g_copy(self, newparent, newname, recursive, _log=True, **kwargs): 

65 """Do nothing. 

66 

67 This method does nothing, but a ``UserWarning`` is issued. 

68 Please note that this method *does not return a new node*, but 

69 ``None``. 

70 

71 """ 

72 

73 warnings.warn( 

74 "UnImplemented node %r does not know how to copy itself; skipping" 

75 % (self._v_pathname,)) 

76 return None # Can you see it? 

77 

78 def _f_copy(self, newparent=None, newname=None, 

79 overwrite=False, recursive=False, createparents=False, 

80 **kwargs): 

81 """Do nothing. 

82 

83 This method does nothing, since `UnImplemented` nodes can not 

84 be copied. However, a ``UserWarning`` is issued. Please note 

85 that this method *does not return a new node*, but ``None``. 

86 

87 """ 

88 

89 # This also does nothing but warn. 

90 self._g_copy(newparent, newname, recursive, **kwargs) 

91 return None # Can you see it? 

92 

93 def __repr__(self): 

94 return """{} 

95 NOTE: <The UnImplemented object represents a PyTables unimplemented 

96 dataset present in the '{}' HDF5 file. If you want to see this 

97 kind of HDF5 dataset implemented in PyTables, please contact the 

98 developers.> 

99""".format(str(self), self._v_file.filename) 

100 

101 

102# Classes reported as H5G_UNKNOWN by HDF5 

103class Unknown(Node): 

104 """This class represents nodes reported as *unknown* by the underlying 

105 HDF5 library. 

106 

107 This class does not have any public instance variables or methods, except 

108 those inherited from the Node class. 

109 

110 """ 

111 

112 # Class identifier 

113 _c_classid = 'UNKNOWN' 

114 

115 def __init__(self, parentnode, name): 

116 """Create the `Unknown` instance.""" 

117 

118 self._v_new = False 

119 super().__init__(parentnode, name) 

120 

121 def _g_new(self, parentnode, name, init=False): 

122 pass 

123 

124 def _g_open(self): 

125 return 0 

126 

127 def _g_copy(self, newparent, newname, recursive, _log=True, **kwargs): 

128 # Silently avoid doing copies of unknown nodes 

129 return None 

130 

131 def _g_delete(self, parent): 

132 pass 

133 

134 def __str__(self): 

135 pathname = self._v_pathname 

136 classname = self.__class__.__name__ 

137 return f"{pathname} ({classname})" 

138 

139 def __repr__(self): 

140 return f"""{self!s} 

141 NOTE: <The Unknown object represents a node which is reported as 

142 unknown by the underlying HDF5 library, but that might be 

143 supported in more recent HDF5 versions.> 

144""" 

145 

146 

147# These are listed here for backward compatibility with PyTables 0.9.x indexes 

148class OldIndexArray(UnImplemented): 

149 _c_classid = 'IndexArray'