bigframes.pandas.DatetimeIndex.astype#

DatetimeIndex.astype(dtype, *, errors: Literal['raise', 'null'] = 'raise') Index#

Create an Index with values cast to dtypes.

The class of a new Index is determined by dtype. When conversion is impossible, a TypeError exception is raised.

Examples:

>>> idx = bpd.Index([1, 2, 3])
>>> idx
Index([1, 2, 3], dtype='Int64')
Parameters:
  • dtype (str, data type, or pandas.ExtensionDtype) – A dtype supported by BigQuery DataFrame include 'boolean', 'Float64', 'Int64', 'int64\[pyarrow\]', 'string', 'string\[pyarrow\]', 'timestamp\[us, tz=UTC\]\[pyarrow\]', 'timestamp\[us\]\[pyarrow\]', 'date32\[day\]\[pyarrow\]', 'time64\[us\]\[pyarrow\]'. A pandas.ExtensionDtype include pandas.BooleanDtype(), pandas.Float64Dtype(), pandas.Int64Dtype(), pandas.StringDtype(storage="pyarrow"), pd.ArrowDtype(pa.date32()), pd.ArrowDtype(pa.time64("us")), pd.ArrowDtype(pa.timestamp("us")), pd.ArrowDtype(pa.timestamp("us", tz="UTC")).

  • errors ({'raise', 'null'}, default 'raise') – Control raising of exceptions on invalid data for provided dtype. If ‘raise’, allow exceptions to be raised if any value fails cast If ‘null’, will assign null value if value fails cast

Returns:

Index with values cast to specified dtype.

Return type:

bigframes.pandas.Index

Raises:
  • ValueError – If errors is not one of raise.

  • TypeError – MultiIndex with more than 1 level does not support astype.