55import numpy as np
66import pandas as pd
77import zstandard
8- from databento .common .data import (
9- CSV_HEADERS ,
10- DBZ_COLUMNS ,
11- DBZ_STRUCT_MAP ,
12- DERIV_SCHEMAS ,
13- )
8+ from databento .common .data import DBZ_COLUMNS , DBZ_STRUCT_MAP , DERIV_SCHEMAS
149from databento .common .enums import Compression , Encoding , Schema , SType
1510from databento .common .logging import log_debug
1611from databento .common .metadata import MetadataDecoder
@@ -65,19 +60,18 @@ def source_metadata(self) -> Dict[str, Any]:
6560 """
6661 log_debug ("Decoding metadata..." )
6762 metadata_initial : bytes = self .reader ().read (8 )
68-
69- if not metadata_initial .startswith (b"Q*M\x18 " ):
70- return {}
71-
7263 magic_bin = metadata_initial [:4 ]
7364 frame_size_bin = metadata_initial [4 :]
7465
66+ if not metadata_initial .startswith (b"P*M\x18 " ):
67+ return {}
68+
7569 metadata_magic = int .from_bytes (bytes = magic_bin , byteorder = "little" )
7670 metadata_frame_size = int .from_bytes (bytes = frame_size_bin , byteorder = "little" )
7771 log_debug (f"magic={ metadata_magic } , frame_size={ metadata_frame_size } " )
7872
7973 metadata_raw = self .reader ().read (8 + metadata_frame_size )
80- return MetadataDecoder .decode_to_json (metadata_raw [ 8 :] )
74+ return MetadataDecoder .decode_to_json (metadata_raw )
8175
8276 def set_metadata (self , metadata : Dict [str , Any ]) -> None :
8377 """
@@ -322,22 +316,6 @@ def limit(self) -> Optional[int]:
322316
323317 return self ._limit
324318
325- @property
326- def encoding (self ) -> Encoding :
327- """
328- Return the data encoding.
329-
330- Returns
331- -------
332- Encoding
333-
334- """
335- if self ._encoding is None :
336- self ._check_metadata ()
337- self ._encoding = Encoding (self ._metadata ["encoding" ])
338-
339- return self ._encoding
340-
341319 @property
342320 def compression (self ) -> Compression :
343321 """
@@ -367,13 +345,9 @@ def shape(self) -> Tuple:
367345 """
368346 if self ._shape is None :
369347 self ._check_metadata ()
370- if self .encoding == Encoding .DBZ :
371- ncols = len (DBZ_STRUCT_MAP [self .schema ])
372- else :
373- ncols = len (CSV_HEADERS [self .schema ])
374348 self ._shape = (
375349 self ._metadata ["record_count" ],
376- ncols ,
350+ len ( DBZ_STRUCT_MAP [ self . schema ]) ,
377351 )
378352
379353 return self ._shape
@@ -395,10 +369,7 @@ def mappings(self) -> List[Dict[str, List[Dict[str, str]]]]:
395369 @property
396370 def symbology (self ) -> Dict [str , Any ]:
397371 """
398- Return the symbology resolution response information for the query.
399-
400- This JSON representable object should exactly match a `symbology.resolve`
401- request using the same query parameters.
372+ Return the symbology resolution information for the query.
402373
403374 Returns
404375 -------
@@ -407,10 +378,12 @@ def symbology(self) -> Dict[str, Any]:
407378 """
408379 self ._check_metadata ()
409380
410- status = self ._metadata ["status" ]
411- if status == 1 :
381+ status = 0
382+ if self ._metadata ["partial" ]:
383+ status = 1
412384 message = "Partially resolved"
413- elif status == 2 :
385+ elif self ._metadata ["not_found" ]:
386+ status = 2
414387 message = "Not found"
415388 else :
416389 message = "OK"
@@ -603,6 +576,72 @@ def to_json(self, path: str) -> None:
603576 """
604577 self .to_df ().to_json (path , orient = "records" , lines = True )
605578
579+ def request_symbology (self , client ) -> Dict [str , Dict [str , Any ]]:
580+ """
581+ Request symbology resolution based on the metadata properties.
582+
583+ Makes a `GET /symbology.resolve` HTTP request.
584+
585+ Current symbology mappings from the metadata are also available by
586+ calling the `.symbology` or `.mappings` properties.
587+
588+ Parameters
589+ ----------
590+ client : Historical
591+ The historical client to use for the request.
592+
593+ Returns
594+ -------
595+ Dict[str, Dict[str, Any]]
596+ A map of input symbol to output symbol across the date range.
597+
598+ """
599+ return client .symbology .resolve (
600+ dataset = self .dataset ,
601+ symbols = self .symbols ,
602+ stype_in = self .stype_in ,
603+ stype_out = self .stype_out ,
604+ start_date = self .start .date (),
605+ end_date = self .end .date (),
606+ )
607+
608+ def request_full_definitions (
609+ self ,
610+ client ,
611+ path : Optional [str ] = None ,
612+ ) -> "Bento" :
613+ """
614+ Request full instrument definitions based on the metadata properties.
615+
616+ Makes a `GET /timeseries.stream` HTTP request.
617+
618+ Parameters
619+ ----------
620+ client : Historical
621+ The historical client to use for the request.
622+ path : str, optional
623+ The file path to write to on disk (if provided).
624+
625+ Returns
626+ -------
627+ Bento
628+
629+ Warnings
630+ --------
631+ Calling this method will incur a cost.
632+
633+ """
634+ return client .timeseries .stream (
635+ dataset = self .dataset ,
636+ symbols = self .symbols ,
637+ schema = Schema .DEFINITION ,
638+ start = self .start ,
639+ end = self .end ,
640+ stype_in = self .stype_in ,
641+ stype_out = self .stype_out ,
642+ path = path ,
643+ )
644+
606645
607646class MemoryBento (Bento ):
608647 """
0 commit comments