diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e417bcd..198150f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -57,7 +57,7 @@ Added - Type annotations support for ORC types. - Support for `timestamp with local time zone` type. - New parameter for Reader and Writer: timezone. -- The backported zoneinfo module dependency pior to Python 3.9. +- The backported zoneinfo module dependency prior to Python 3.9. - Predicate (SearchArgument) support for filtering row groups during ORC file reads. New classes: Predicate and PredicateColumn. - New parameter for Reader: predicate. diff --git a/docs/api.rst b/docs/api.rst index 6d74205..98b5c34 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -141,7 +141,7 @@ API documentation =============== .. class:: Reader(fileo, batch_size=1024, column_indices=None, \ - column_names=None, timezone=zoneinfo.ZoneInfo("UTC"), \ + column_names=None, timezone=datetime.timezone.utc, \ struct_repr=StructRepr.TUPLE, converters=None, \ predicate=None, null_value=None) @@ -531,7 +531,7 @@ API documentation compression=CompressionKind.ZLIB, \ compression_strategy=CompressionStrategy.SPEED, \ compression_block_size=65536, bloom_filter_columns=None, \ - bloom_filter_fpp=0.05, timezone=zoneinfo.ZoneInfo("UTC"), \ + bloom_filter_fpp=0.05, timezone=datetime.timezone.utc, \ struct_repr=StructRepr.TUPLE, converters=None, \ padding_tolerance=0.0, dict_key_size_threshold=0.0, \ null_value=None) diff --git a/setup.py b/setup.py index 6f84c41..0c5d9be 100644 --- a/setup.py +++ b/setup.py @@ -260,6 +260,5 @@ def build_extensions(self): python_requires=">=3.6", install_requires=[ 'tzdata >= 2020.5 ; sys_platform == "win32"', - 'backports.zoneinfo >= 0.2.1 ; python_version < "3.9"', ], ) diff --git a/src/pyorc/converters.py b/src/pyorc/converters.py index 2c5c787..24a25d6 100644 --- a/src/pyorc/converters.py +++ b/src/pyorc/converters.py @@ -1,16 +1,11 @@ from abc import ABC, abstractmethod -from datetime import date, datetime, timedelta, timezone as tz +from datetime import date, datetime, timedelta, timezone as tz, tzinfo from decimal import Decimal, localcontext import math from typing import Dict, Tuple, Type from .enums import TypeKind -try: - import zoneinfo -except ImportError: - from backports import zoneinfo - class ORCConverter(ABC): @staticmethod @@ -27,7 +22,7 @@ def to_orc(*args): class TimestampConverter(ORCConverter): @staticmethod def from_orc( - seconds: int, nanoseconds: int, timezone: zoneinfo.ZoneInfo, + seconds: int, nanoseconds: int, timezone: tzinfo, ) -> datetime: epoch = datetime(1970, 1, 1, 0, 0, 0, tzinfo=tz.utc) return ( @@ -35,7 +30,7 @@ def from_orc( ).astimezone(timezone) @staticmethod - def to_orc(obj: datetime, timezone: zoneinfo.ZoneInfo) -> Tuple[int, int]: + def to_orc(obj: datetime, timezone: tzinfo) -> Tuple[int, int]: return math.floor(obj.timestamp()), obj.microsecond * 1000 diff --git a/src/pyorc/reader.py b/src/pyorc/reader.py index bf96bd2..7b31702 100644 --- a/src/pyorc/reader.py +++ b/src/pyorc/reader.py @@ -1,4 +1,5 @@ from collections import defaultdict +from datetime import timezone, tzinfo from typing import Any, BinaryIO, Dict, Iterator, List, Optional, Type from pyorc._pyorc import reader, stripe @@ -7,11 +8,6 @@ from .enums import CompressionKind, StructRepr, TypeKind, WriterVersion from .predicates import Predicate -try: - import zoneinfo -except ImportError: - from backports import zoneinfo - class Column: def __init__(self, stream, index): @@ -57,7 +53,7 @@ def __init__( batch_size: int = 1024, column_indices: Optional[List[int]] = None, column_names: Optional[List[str]] = None, - timezone: zoneinfo.ZoneInfo = zoneinfo.ZoneInfo("UTC"), + timezone: tzinfo = timezone.utc, struct_repr: StructRepr = StructRepr.TUPLE, converters: Optional[Dict[TypeKind, Type[ORCConverter]]] = None, predicate: Optional[Predicate] = None, diff --git a/src/pyorc/writer.py b/src/pyorc/writer.py index dbafbb7..10190f7 100644 --- a/src/pyorc/writer.py +++ b/src/pyorc/writer.py @@ -1,4 +1,5 @@ import copy +from datetime import timezone, tzinfo from typing import Any, BinaryIO, Dict, List, Optional, Type, Union from pyorc._pyorc import writer @@ -7,11 +8,6 @@ from .enums import CompressionKind, CompressionStrategy, StructRepr, TypeKind from .typedescription import TypeDescription -try: - import zoneinfo -except ImportError: - from backports import zoneinfo - class Writer(writer): def __init__( @@ -26,7 +22,7 @@ def __init__( compression_block_size: int = 65536, bloom_filter_columns: Optional[List] = None, bloom_filter_fpp: float = 0.05, - timezone: zoneinfo.ZoneInfo = zoneinfo.ZoneInfo("UTC"), + timezone: tzinfo = timezone.utc, struct_repr: StructRepr = StructRepr.TUPLE, converters: Optional[Dict[TypeKind, Type[ORCConverter]]] = None, padding_tolerance: float = 0.0,