Skip to content

Commit

Permalink
Merge branch 'devel' into d#/fix_import_schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Mar 5, 2024
2 parents 6c27211 + 483d4ae commit ba449a4
Show file tree
Hide file tree
Showing 67 changed files with 2,492 additions and 966 deletions.
4 changes: 4 additions & 0 deletions dlt/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from dlt.cli._dlt import main

if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Any, ClassVar, Dict, List, Optional
from sqlalchemy.engine import URL, make_url
from dlt.common.libs.sql_alchemy import URL, make_url
from dlt.common.configuration.specs.exceptions import InvalidConnectionString

from dlt.common.typing import TSecretValue
Expand All @@ -26,6 +26,7 @@ def parse_native_representation(self, native_value: Any) -> None:
# update only values that are not None
self.update({k: v for k, v in url._asdict().items() if v is not None})
if self.query is not None:
# query may be immutable so make it mutable
self.query = dict(self.query)
except Exception:
raise InvalidConnectionString(self.__class__, native_value, self.drivername)
Expand Down
1 change: 0 additions & 1 deletion dlt/common/data_types/type_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from dlt.common.data_types.typing import TDataType
from dlt.common.time import (
ensure_pendulum_datetime,
parse_iso_like_datetime,
ensure_pendulum_date,
ensure_pendulum_time,
)
Expand Down
6 changes: 6 additions & 0 deletions dlt/common/libs/numpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from dlt.common.exceptions import MissingDependencyException

try:
import numpy
except ModuleNotFoundError:
raise MissingDependencyException("DLT Numpy Helpers", ["numpy"])
10 changes: 6 additions & 4 deletions dlt/common/libs/pyarrow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime, date # noqa: I251
from pendulum.tz import UTC
from typing import Any, Tuple, Optional, Union, Callable, Iterable, Iterator, Sequence, Tuple

from dlt import version
Expand All @@ -14,6 +15,7 @@
try:
import pyarrow
import pyarrow.parquet
import pyarrow.compute
except ModuleNotFoundError:
raise MissingDependencyException(
"dlt parquet Helpers", [f"{version.DLT_PKG_NAME}[parquet]"], "dlt Helpers for for parquet."
Expand Down Expand Up @@ -314,21 +316,21 @@ def is_arrow_item(item: Any) -> bool:
return isinstance(item, (pyarrow.Table, pyarrow.RecordBatch))


def to_arrow_compute_input(value: Any, arrow_type: pyarrow.DataType) -> Any:
def to_arrow_scalar(value: Any, arrow_type: pyarrow.DataType) -> Any:
"""Converts python value to an arrow compute friendly version"""
return pyarrow.scalar(value, type=arrow_type)


def from_arrow_compute_output(arrow_value: pyarrow.Scalar) -> Any:
"""Converts arrow scalar into Python type. Currently adds "UTC" to naive date times."""
def from_arrow_scalar(arrow_value: pyarrow.Scalar) -> Any:
"""Converts arrow scalar into Python type. Currently adds "UTC" to naive date times and converts all others to UTC"""
row_value = arrow_value.as_py()
# dates are not represented as datetimes but I see connector-x represents
# datetimes as dates and keeping the exact time inside. probably a bug
# but can be corrected this way
if isinstance(row_value, date) and not isinstance(row_value, datetime):
row_value = pendulum.from_timestamp(arrow_value.cast(pyarrow.int64()).as_py() / 1000)
elif isinstance(row_value, datetime):
row_value = pendulum.instance(row_value)
row_value = pendulum.instance(row_value).in_tz("UTC")
return row_value


Expand Down
Loading

0 comments on commit ba449a4

Please sign in to comment.