ipad package

ipad.read(*, schema, query, types=[], cur=None)

执行 sql 语句并回读数据。

types: 可选显式指定返回列的类型。支持输入

  • 表 (如 database.stock.stock_in_day): 使用表中所有列的类型

  • 列 (如 database.stock.stock_in_day.high): 使用给定列的类型

  • 名称到 py 类型映射 (如 {“col1”: float, “col2”: str}): str, int, float, bool

  • 名称到 df 类型映射 (如 {“col1”: polars.Int32, “col2”: polars.Boolean})

  • 上述内容的列表 (如 [database.stock.stock_in_day, {“col1”: float}]): 重复项取最后出现的类型

例:

import ipad.database
import ipad.stock

df = ipad.read(
    schema="stock",
    query="""
    select open,high,close,low,stock_code,candle_end_time,hushen300,zhongzheng500
    from stock_in_day
    where candle_end_time
        between '2022-01-01' and '2022-01-09'
    """,
    types=ipad.stock.stock_in_day,
)

print(df)
参数:
  • schema (Literal['b'] | ~typing.Literal['stock']) –

  • query (str) –

  • types (type[BaseExt] | Column | dict[str, type[DataType] | type[int] | type[float] | type[str] | type[bool]] | list[type[BaseExt] | Column | dict[str, type[DataType] | type[int] | type[float] | type[str] | type[bool]]]) –

  • cur (DBAPICursor | None) –

ipad.write(table, df, *, cur=None)

写入 DataFrame 到数据库。需手动确保输入各列类型与数据库兼容

参数:
  • table (Any) –

  • df (DataFrame) –

  • cur (DBAPICursor | None) –

Subpackages

Submodules