@@ -100,7 +100,7 @@ def __init__(self, dataobject, pseudo_chunking_size_MB=4):
100100 # throws a flake8 wobbly for Python<3.10; match is Py3.10+ syntax
101101 match self .layout_class : # noqa
102102 case 0 : #compact storage
103- raise NotImplementedError ( "Compact Storage" )
103+ self . _data = self . _get_compact_data ( dataobject )
104104 case 1 : # contiguous storage
105105 self .data_offset , = struct .unpack_from ('<Q' , dataobject .msg_data , self .property_offset )
106106 case 2 : # chunked storage
@@ -156,14 +156,14 @@ def read_direct_chunk(self, chunk_position, **kwargs):
156156 raise OSError ("Chunk coordinates must lie on chunk boundaries" )
157157 storeinfo = self ._index [chunk_position ]
158158 return storeinfo .filter_mask , self ._get_raw_chunk (storeinfo )
159-
159+
160160 def get_data (self , args , fillvalue ):
161161 """ Called by the dataset getitem method """
162162 dtype = self ._dtype
163163 # throws a flake8 wobbly for Python<3.10; match is Py3.10+ syntax
164164 match self .layout_class : # noqa
165165 case 0 : #compact storage
166- raise NotImplementedError ( "Compact Storage" )
166+ return self . _read_compact_data ( args , fillvalue )
167167 case 1 : # contiguous storage
168168 if self .data_offset == UNDEFINED_ADDRESS :
169169 # no storage is backing array, return an array of
@@ -375,6 +375,40 @@ def _get_contiguous_data(self, args):
375375 except UnsupportedOperation :
376376 return self ._get_direct_from_contiguous (args )
377377
378+ def _get_compact_data (self , dataobject ):
379+ data = None
380+ layout = None
381+ for msg in dataobject .msgs :
382+ if msg ["type" ] == 8 :
383+ layout = msg
384+ break
385+ if layout is None :
386+ raise ValueError ("No layout message in compact dataset?" )
387+ byts = dataobject .msg_data [msg ["offset_to_message" ]:msg ["offset_to_message" ]+ msg ["size" ]]
388+ layout_version = byts [0 ]
389+ if layout_version == 1 or layout_version == 2 :
390+ raise NotImplementedError ("Compact layout v1 and v2." )
391+ elif layout_version == 3 or layout_version == 4 :
392+ size = int .from_bytes (byts [2 :4 ], "little" )
393+ data = byts [4 :4 + size ]
394+ else :
395+ raise ValueError ("Unknown layout version." )
396+ return data
397+
398+ def _read_compact_data (self , args , fillvalue ):
399+ if self ._data is None :
400+ if isinstance (self ._dtype , tuple ):
401+ dtype = np .array (fillvalue ).dtype
402+ return np .full (self .shape , fillvalue , dtype = dtype )[args ]
403+ else :
404+ view = np .frombuffer (
405+ self ._data ,
406+ dtype = self ._dtype ,
407+ ).reshape (self .shape )
408+ # Create the sub-array
409+ result = view [args ]
410+ return result
411+
378412
379413 def _get_direct_from_contiguous (self , args = None ):
380414 """
0 commit comments