API Reference¶
Pandas Data Types for SQL systems (BigQuery, Spanner)
- class db_dtypes.DateArray(values, dtype=None, copy: bool = False)[source]¶
Pandas array type containing date data
- astype(dtype, copy=True)[source]¶
Cast to a NumPy array or ExtensionArray with ‘dtype’.
- Parameters
- Returns
An
ExtensionArray
ifdtype
isExtensionDtype
, otherwise a Numpy ndarray withdtype
for its dtype.- Return type
np.ndarray or pandas.api.extensions.ExtensionArray
Examples
>>> arr = pd.array([1, 2, 3]) >>> arr <IntegerArray> [1, 2, 3] Length: 3, dtype: Int64
Casting to another
ExtensionDtype
returns anExtensionArray
:>>> arr1 = arr.astype('Float64') >>> arr1 <FloatingArray> [1.0, 2.0, 3.0] Length: 3, dtype: Float64 >>> arr1.dtype Float64Dtype()
Otherwise, we will get a Numpy ndarray:
>>> arr2 = arr.astype('float64') >>> arr2 array([1., 2., 3.]) >>> arr2.dtype dtype('float64')
- class db_dtypes.DateDtype[source]¶
Extension dtype for time data.
- static __from_arrow__(array: Union[pyarrow.lib.Array, pyarrow.lib.ChunkedArray]) db_dtypes.DateArray [source]¶
Convert to dbdate data from an Arrow array.
- type¶
alias of
datetime.date
- class db_dtypes.JSONArray(values)[source]¶
Extension array that handles BigQuery JSON data, leveraging a string-based pyarrow array for storage. It enables seamless conversion to JSON objects when accessing individual elements.
- __array__(dtype=None, copy: Optional[bool] = None) numpy.ndarray [source]¶
Correctly construct numpy arrays when passed to np.asarray().
- __arrow_array__(type=None)[source]¶
Convert to an arrow array. This is required for pyarrow extension.
- property dtype: db_dtypes.json.JSONDtype¶
An instance of JSONDtype
- property pa_data¶
An instance of stored pa data
- class db_dtypes.JSONArrowType[source]¶
Arrow extension type for the dbjson Pandas extension type.
Initialize an extension type instance.
This should be called at the end of the subclass’
__init__
method.
- class db_dtypes.JSONDtype[source]¶
Extension dtype for BigQuery JSON data.
- __from_arrow__(array: pyarrow.lib.Array | pyarrow.lib.ChunkedArray) db_dtypes.json.JSONArray [source]¶
Convert the pyarrow array to the extension array.
- property na_value: pd.NA¶
Default NA value to use for this type.
- property pyarrow_dtype¶
Return the pyarrow data type used for storing data in the pyarrow array.
- class db_dtypes.TimeArray(values, dtype=None, copy: bool = False)[source]¶
Pandas array type containing time data
- astype(dtype, copy=True)[source]¶
Cast to a NumPy array or ExtensionArray with ‘dtype’.
- Parameters
- Returns
An
ExtensionArray
ifdtype
isExtensionDtype
, otherwise a Numpy ndarray withdtype
for its dtype.- Return type
np.ndarray or pandas.api.extensions.ExtensionArray
Examples
>>> arr = pd.array([1, 2, 3]) >>> arr <IntegerArray> [1, 2, 3] Length: 3, dtype: Int64
Casting to another
ExtensionDtype
returns anExtensionArray
:>>> arr1 = arr.astype('Float64') >>> arr1 <FloatingArray> [1.0, 2.0, 3.0] Length: 3, dtype: Float64 >>> arr1.dtype Float64Dtype()
Otherwise, we will get a Numpy ndarray:
>>> arr2 = arr.astype('float64') >>> arr2 array([1., 2., 3.]) >>> arr2.dtype dtype('float64')
- class db_dtypes.TimeDtype[source]¶
Extension dtype for time data.
- static __from_arrow__(array: Union[pyarrow.lib.Array, pyarrow.lib.ChunkedArray]) db_dtypes.TimeArray [source]¶
Convert to dbtime data from an Arrow array.
- type¶
alias of
datetime.time