Skip to content

Commit

Permalink
Merge pull request #605 from zen-xu/standard-collections-type-hint
Browse files Browse the repository at this point in the history
typing: support type hint with standard collections
  • Loading branch information
wangxiaoying authored Apr 17, 2024
2 parents 87dc1d2 + bdcdba4 commit 8b67c11
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions connectorx-python/connectorx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Optional, Tuple, Union, List, Dict, Any
from __future__ import annotations

from typing import Any

from importlib.metadata import version

Expand Down Expand Up @@ -27,7 +29,7 @@
)


def rewrite_conn(conn: str, protocol: Optional[str] = None):
def rewrite_conn(conn: str, protocol: str | None = None):
if not protocol:
# note: redshift/clickhouse are not compatible with the 'binary' protocol, and use other database
# drivers to connect. set a compatible protocol and masquerade as the appropriate backend.
Expand All @@ -46,7 +48,7 @@ def rewrite_conn(conn: str, protocol: Optional[str] = None):
def get_meta(
conn: str,
query: str,
protocol: Optional[str] = None,
protocol: str | None = None,
):
"""
Get metadata (header) of the given query (only for pandas)
Expand All @@ -73,7 +75,7 @@ def partition_sql(
query: str,
partition_on: str,
partition_num: int,
partition_range: Optional[Tuple[int, int]] = None,
partition_range: tuple[int, int] | None = None,
):
"""
Partition the sql query
Expand Down Expand Up @@ -102,13 +104,13 @@ def partition_sql(


def read_sql_pandas(
sql: Union[List[str], str],
con: Union[str, Dict[str, str]],
index_col: Optional[str] = None,
protocol: Optional[str] = None,
partition_on: Optional[str] = None,
partition_range: Optional[Tuple[int, int]] = None,
partition_num: Optional[int] = None,
sql: list[str] | str,
con: str | dict[str, str],
index_col: str | None = None,
protocol: str | None = None,
partition_on: str | None = None,
partition_range: tuple[int, int] | None = None,
partition_num: int | None = None,
):
"""
Run the SQL query, download the data from database into a dataframe.
Expand Down Expand Up @@ -142,15 +144,15 @@ def read_sql_pandas(


def read_sql(
conn: Union[str, Dict[str, str]],
query: Union[List[str], str],
conn: str | dict[str, str],
query: list[str] | str,
*,
return_type: str = "pandas",
protocol: Optional[str] = None,
partition_on: Optional[str] = None,
partition_range: Optional[Tuple[int, int]] = None,
partition_num: Optional[int] = None,
index_col: Optional[str] = None,
protocol: str | None = None,
partition_on: str | None = None,
partition_range: tuple[int, int] | None = None,
partition_num: int | None = None,
index_col: str | None = None,
):
"""
Run the SQL query, download the data from database into a dataframe.
Expand Down Expand Up @@ -319,7 +321,7 @@ def read_sql(
return df


def reconstruct_arrow(result: Tuple[List[str], List[List[Tuple[int, int]]]]):
def reconstruct_arrow(result: tuple[list[str], list[list[tuple[int, int]]]]):
import pyarrow as pa

names, ptrs = result
Expand All @@ -335,7 +337,7 @@ def reconstruct_arrow(result: Tuple[List[str], List[List[Tuple[int, int]]]]):
return pa.Table.from_batches(rbs)


def reconstruct_pandas(df_infos: Dict[str, Any]):
def reconstruct_pandas(df_infos: dict[str, Any]):
import pandas as pd

data = df_infos["data"]
Expand Down

0 comments on commit 8b67c11

Please sign in to comment.