Pandas Data Types for SQL Systems

1.5.0 · active · verified Sun Mar 29

db-dtypes is a specialized Python library that provides Pandas Extension Dtypes to represent and interact with data types commonly found in relational databases, particularly BigQuery and Spanner. It aims to ensure data integrity and improve performance by providing faithful representations of types like Date, Time, and JSON. The library is actively maintained by Google, with multiple releases per year, and its current version is 1.5.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize pandas Series with custom `dbdate`, `dbtime`, and `dbjson` dtypes provided by the `db-dtypes` library. The initial `import db_dtypes` is crucial for registering these extension types with pandas.

import datetime
import pandas as pd
import db_dtypes # noqa: F401

# Using dbdate dtype
dates = pd.Series([datetime.date(2023, 1, 1), '2023-01-02'], dtype='dbdate')
print('Dates Series:')
print(dates)

# Using dbtime dtype
times = pd.Series([datetime.time(10, 30, 0), '15:45:00.123'], dtype='dbtime')
print('\nTimes Series:')
print(times)

# Using dbjson dtype
json_data = pd.Series([{'key': 'value'}, [1, 2, 3], 'null'], dtype='dbjson')
print('\nJSON Series:')
print(json_data)

view raw JSON →