3131)
3232from databento .common .enums import Compression , Schema , SType
3333from databento .common .error import BentoError
34- from databento .common .metadata import MetadataDecoder
3534from databento .common .symbology import InstrumentIdMappingInterval
35+ from databento_dbn import Metadata
3636
3737
3838logger = logging .getLogger (__name__ )
@@ -195,7 +195,7 @@ class MemoryDataSource(DataSource):
195195
196196 """
197197
198- def __init__ (self , source : Union [BytesIO , bytes ]):
198+ def __init__ (self , source : Union [BytesIO , bytes , IO [ bytes ] ]):
199199 initial_data = source if isinstance (source , bytes ) else source .read ()
200200 if len (initial_data ) == 0 :
201201 raise ValueError (
@@ -334,7 +334,7 @@ def __init__(self, data_source: DataSource) -> None:
334334 metadata_bytes .write (buffer .read (metadata_length ))
335335
336336 # Read metadata
337- self ._metadata : Dict [ str , Any ] = MetadataDecoder (). decode_to_json (
337+ self ._metadata : Metadata = Metadata . decode (
338338 metadata_bytes .getvalue (),
339339 )
340340
@@ -408,7 +408,7 @@ def _build_instrument_id_index(self) -> Dict[dt.date, Dict[int, str]]:
408408 ),
409409 )
410410
411- product_id_index : Dict [dt .date , Dict [int , str ]] = {}
411+ instrument_id_index : Dict [dt .date , Dict [int , str ]] = {}
412412 for interval in intervals :
413413 for ts in pd .date_range (
414414 start = interval .start_date ,
@@ -417,12 +417,12 @@ def _build_instrument_id_index(self) -> Dict[dt.date, Dict[int, str]]:
417417 ** {"inclusive" if pd .__version__ >= "1.4.0" else "closed" : "left" },
418418 ):
419419 d : dt .date = ts .date ()
420- date_map : Dict [int , str ] = product_id_index .get (d , {})
420+ date_map : Dict [int , str ] = instrument_id_index .get (d , {})
421421 if not date_map :
422- product_id_index [d ] = date_map
422+ instrument_id_index [d ] = date_map
423423 date_map [interval .instrument_id ] = interval .raw_symbol
424424
425- return product_id_index
425+ return instrument_id_index
426426
427427 def _prepare_dataframe (self , df : pd .DataFrame ) -> pd .DataFrame :
428428 # Setup column ordering and index
@@ -495,7 +495,7 @@ def dataset(self) -> str:
495495 str
496496
497497 """
498- return str (self ._metadata [ " dataset" ] )
498+ return str (self ._metadata . dataset )
499499
500500 @property
501501 def dtype (self ) -> np .dtype [Any ]:
@@ -523,7 +523,7 @@ def end(self) -> pd.Timestamp:
523523 The data timestamps will not occur after `end`.
524524
525525 """
526- return pd .Timestamp (self ._metadata [ " end" ] , tz = "UTC" )
526+ return pd .Timestamp (self ._metadata . end , tz = "UTC" )
527527
528528 @property
529529 def limit (self ) -> Optional [int ]:
@@ -535,7 +535,7 @@ def limit(self) -> Optional[int]:
535535 int or None
536536
537537 """
538- return self ._metadata [ " limit" ]
538+ return self ._metadata . limit
539539
540540 @property
541541 def nbytes (self ) -> int :
@@ -559,16 +559,16 @@ def mappings(self) -> Dict[str, List[Dict[str, Any]]]:
559559 Dict[str, List[Dict[str, Any]]]
560560
561561 """
562- return self ._metadata [ " mappings" ]
562+ return self ._metadata . mappings
563563
564564 @property
565- def metadata (self ) -> Dict [ str , Any ] :
565+ def metadata (self ) -> Metadata :
566566 """
567567 Return the metadata for the data.
568568
569569 Returns
570570 -------
571- Dict[str, Any]
571+ Metadata
572572
573573 """
574574 return self ._metadata
@@ -624,7 +624,7 @@ def schema(self) -> Schema:
624624 Schema
625625
626626 """
627- return Schema (self ._metadata [ " schema" ] )
627+ return Schema (self ._metadata . schema )
628628
629629 @property
630630 def start (self ) -> pd .Timestamp :
@@ -640,7 +640,7 @@ def start(self) -> pd.Timestamp:
640640 The data timestamps will not occur prior to `start`.
641641
642642 """
643- return pd .Timestamp (self ._metadata [ " start" ] , tz = "UTC" )
643+ return pd .Timestamp (self ._metadata . start , tz = "UTC" )
644644
645645 @property
646646 def record_size (self ) -> int :
@@ -664,7 +664,7 @@ def stype_in(self) -> SType:
664664 SType
665665
666666 """
667- return SType (self ._metadata [ " stype_in" ] )
667+ return SType (self ._metadata . stype_in )
668668
669669 @property
670670 def stype_out (self ) -> SType :
@@ -676,7 +676,7 @@ def stype_out(self) -> SType:
676676 SType
677677
678678 """
679- return SType (self ._metadata [ " stype_out" ] )
679+ return SType (self ._metadata . stype_out )
680680
681681 @property
682682 def symbology (self ) -> Dict [str , Any ]:
@@ -694,8 +694,8 @@ def symbology(self) -> Dict[str, Any]:
694694 "stype_out" : str (self .stype_out ),
695695 "start_date" : str (self .start .date ()),
696696 "end_date" : str (self .end .date ()),
697- "partial" : self ._metadata [ " partial" ] ,
698- "not_found" : self ._metadata [ " not_found" ] ,
697+ "partial" : self ._metadata . partial ,
698+ "not_found" : self ._metadata . not_found ,
699699 "mappings" : self .mappings ,
700700 }
701701
@@ -709,7 +709,7 @@ def symbols(self) -> List[str]:
709709 List[str]
710710
711711 """
712- return self ._metadata [ " symbols" ]
712+ return self ._metadata . symbols
713713
714714 @classmethod
715715 def from_file (cls , path : Union [PathLike [str ], str ]) -> "DBNStore" :
0 commit comments