4747from databento .common .constants import DEFINITION_TYPE_MAX_MAP
4848from databento .common .constants import SCHEMA_STRUCT_MAP
4949from databento .common .constants import SCHEMA_STRUCT_MAP_V1
50+ from databento .common .enums import PriceType
5051from databento .common .error import BentoError
5152from databento .common .error import BentoWarning
5253from databento .common .symbology import InstrumentMap
@@ -848,7 +849,7 @@ def to_csv(
848849 @overload
849850 def to_df (
850851 self ,
851- price_type : Literal [ "fixed" , "float" , "decimal" ] = ...,
852+ price_type : PriceType | str = ...,
852853 pretty_ts : bool = ...,
853854 map_symbols : bool = ...,
854855 schema : Schema | str | None = ...,
@@ -859,7 +860,7 @@ def to_df(
859860 @overload
860861 def to_df (
861862 self ,
862- price_type : Literal [ "fixed" , "float" , "decimal" ] = ...,
863+ price_type : PriceType | str = ...,
863864 pretty_ts : bool = ...,
864865 map_symbols : bool = ...,
865866 schema : Schema | str | None = ...,
@@ -869,7 +870,7 @@ def to_df(
869870
870871 def to_df (
871872 self ,
872- price_type : Literal [ "fixed" , "float" , "decimal" ] = "float" ,
873+ price_type : PriceType | str = PriceType . FLOAT ,
873874 pretty_ts : bool = True ,
874875 map_symbols : bool = True ,
875876 schema : Schema | str | None = None ,
@@ -883,7 +884,7 @@ def to_df(
883884
884885 Parameters
885886 ----------
886- price_type : str, default "float"
887+ price_type : PriceType or str, default "float"
887888 The price type to use for price fields.
888889 If "fixed", prices will have a type of `int` in fixed decimal format; each unit representing 1e-9 or 0.000000001.
889890 If "float", prices will have a type of `float`.
@@ -918,6 +919,7 @@ def to_df(
918919 If the DBN schema is unspecified and cannot be determined.
919920
920921 """
922+ price_type = validate_enum (price_type , PriceType , "price_type" )
921923 schema = validate_maybe_enum (schema , Schema , "schema" )
922924
923925 if isinstance (tz , Default ):
@@ -1422,7 +1424,7 @@ def __init__(
14221424 struct_type : type [DBNRecord ],
14231425 instrument_map : InstrumentMap ,
14241426 tz : pytz .BaseTzInfo ,
1425- price_type : Literal [ "fixed" , "float" , "decimal" ] = "float" ,
1427+ price_type : PriceType = PriceType . FLOAT ,
14261428 pretty_ts : bool = True ,
14271429 map_symbols : bool = True ,
14281430 ):
@@ -1499,16 +1501,16 @@ def _format_timezone(self, df: pd.DataFrame) -> None:
14991501 def _format_px (
15001502 self ,
15011503 df : pd .DataFrame ,
1502- price_type : Literal [ "fixed" , "float" , "decimal" ] ,
1504+ price_type : PriceType ,
15031505 ) -> None :
15041506 px_fields = self ._struct_type ._price_fields
15051507
1506- if price_type == "decimal" :
1508+ if price_type == PriceType . DECIMAL :
15071509 df [px_fields ] = (
15081510 df [px_fields ].replace (UNDEF_PRICE , np .nan ).applymap (decimal .Decimal )
15091511 / FIXED_PRICE_SCALE
15101512 )
1511- elif price_type == "float" :
1513+ elif price_type == PriceType . FLOAT :
15121514 df [px_fields ] = df [px_fields ].replace (UNDEF_PRICE , np .nan ) / FIXED_PRICE_SCALE
15131515 else :
15141516 return # do nothing
0 commit comments