As of January 1, 2020 this library no longer supports Python 2 on the latest released version. Library versions released prior to that date will continue to be available. For more information please visit Python 2 support on Google Cloud.

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

__arrow_array__(type=None)[source]

Convert to an Arrow array from dbdate data.

See: https://pandas.pydata.org/pandas-docs/stable/development/extending.html#compatibility-with-apache-arrow

astype(dtype, copy=True)[source]

Cast to a NumPy array or ExtensionArray with ‘dtype’.

Parameters
  • dtype (str or dtype) – Typecode or data-type to which the array is cast.

  • copy (bool, default True) – Whether to copy the data, even if not necessary. If False, a copy is made only if the old dtype does not match the new dtype.

Returns

An ExtensionArray if dtype is ExtensionDtype, otherwise a Numpy ndarray with dtype 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 an ExtensionArray:

>>> 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.

See: https://pandas.pydata.org/pandas-docs/stable/development/extending.html#compatibility-with-apache-arrow

construct_array_type()[source]

Return the array type associated with this dtype.

Returns

Return type

type

type

alias of datetime.date

class db_dtypes.TimeArray(values, dtype=None, copy: bool = False)[source]

Pandas array type containing time data

__arrow_array__(type=None)[source]

Convert to an Arrow array from dbtime data.

See: https://pandas.pydata.org/pandas-docs/stable/development/extending.html#compatibility-with-apache-arrow

astype(dtype, copy=True)[source]

Cast to a NumPy array or ExtensionArray with ‘dtype’.

Parameters
  • dtype (str or dtype) – Typecode or data-type to which the array is cast.

  • copy (bool, default True) – Whether to copy the data, even if not necessary. If False, a copy is made only if the old dtype does not match the new dtype.

Returns

An ExtensionArray if dtype is ExtensionDtype, otherwise a Numpy ndarray with dtype 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 an ExtensionArray:

>>> 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.

See: https://pandas.pydata.org/pandas-docs/stable/development/extending.html#compatibility-with-apache-arrow

construct_array_type()[source]

Return the array type associated with this dtype.

Returns

Return type

type

type

alias of datetime.time