11from __future__ import annotations
22
33import abc
4+ import datetime
45import decimal
56import itertools
67import logging
78import warnings
9+ import zoneinfo
810from collections .abc import Generator
911from collections .abc import Iterator
1012from collections .abc import Mapping
2830import pandas as pd
2931import pyarrow as pa
3032import pyarrow .parquet as pq
31- import pytz
3233import zstandard
3334from databento_dbn import FIXED_PRICE_SCALE
3435from databento_dbn import UNDEF_PRICE
@@ -859,7 +860,7 @@ def to_df(
859860 pretty_ts : bool = ...,
860861 map_symbols : bool = ...,
861862 schema : Schema | str | None = ...,
862- tz : pytz . BaseTzInfo | str = ...,
863+ tz : datetime . tzinfo | str = ...,
863864 count : None = ...,
864865 ) -> pd .DataFrame : ...
865866
@@ -870,7 +871,7 @@ def to_df(
870871 pretty_ts : bool = ...,
871872 map_symbols : bool = ...,
872873 schema : Schema | str | None = ...,
873- tz : pytz . BaseTzInfo | str = ...,
874+ tz : datetime . tzinfo | str = ...,
874875 count : int = ...,
875876 ) -> DataFrameIterator : ...
876877
@@ -880,8 +881,8 @@ def to_df(
880881 pretty_ts : bool = True ,
881882 map_symbols : bool = True ,
882883 schema : Schema | str | None = None ,
883- tz : pytz . BaseTzInfo | str | Default [pytz . BaseTzInfo ] = Default [pytz . BaseTzInfo ](
884- pytz . UTC ,
884+ tz : datetime . tzinfo | str | Default [datetime . tzinfo ] = Default [datetime . tzinfo ](
885+ datetime . timezone . utc ,
885886 ),
886887 count : int | None = None ,
887888 ) -> pd .DataFrame | DataFrameIterator :
@@ -909,7 +910,7 @@ def to_df(
909910 schema : Schema or str, optional
910911 The DBN schema for the dataframe.
911912 This is only required when reading a DBN stream with mixed record types.
912- tz : pytz.BaseTzInfo or str, default UTC
913+ tz : datetime.tzinfo or str, default UTC
913914 If `pretty_ts` is `True`, all timestamps will be converted to the specified timezone.
914915 count : int, optional
915916 If set, instead of returning a single `DataFrame` a `DataFrameIterator`
@@ -939,8 +940,13 @@ def to_df(
939940 "A timezone was specified when `pretty_ts` is `False`. Did you mean to set `pretty_ts=True`?" ,
940941 )
941942
942- if not isinstance (tz , pytz .BaseTzInfo ):
943- tz = pytz .timezone (tz )
943+ if isinstance (tz , str ):
944+ tz = zoneinfo .ZoneInfo (tz )
945+ elif not isinstance (tz , datetime .tzinfo ):
946+ raise ValueError (
947+ f"The value { tz !r} is not a valid datetime.tzinfo" ,
948+ )
949+
944950 if schema is None :
945951 if self .schema is None :
946952 raise ValueError ("a schema must be specified for mixed DBN data" )
@@ -1442,7 +1448,7 @@ def __init__(
14421448 count : int | None ,
14431449 struct_type : type [DBNRecord ],
14441450 instrument_map : InstrumentMap ,
1445- tz : pytz . BaseTzInfo ,
1451+ tz : datetime . tzinfo ,
14461452 price_type : PriceType = PriceType .FLOAT ,
14471453 pretty_ts : bool = True ,
14481454 map_symbols : bool = True ,
0 commit comments