larray.Axis.astype¶
-
Axis.
astype
(dtype: Union[str, numpy.dtype], casting: str = 'unsafe') → larray.core.axis.Axis[source]¶ Cast labels to a specified type.
Parameters: - dtype: str or dtype
Typecode or data-type to which the labels are cast.
- casting: str, optional
Controls what kind of data casting may occur. Defaults to unsafe.
- no means the data types should not be cast at all.
- equiv means only byte-order changes are allowed.
- safe means only casts which can preserve values are allowed.
- same_kind means only safe casts or casts within a kind, like float64 to float32, are allowed.
- unsafe means any data conversions may be done.
Returns: - Axis
Axis with labels converted to the new type.
Examples
>>> from larray import ndtest >>> arr = ndtest('time=2015..2020') >>> arr = arr.with_total() >>> arr time 2015 2016 2017 2018 2019 2020 total 0 1 2 3 4 5 15 >>> arr = arr.drop('total') >>> time = arr.time >>> time Axis([2015, 2016, 2017, 2018, 2019, 2020], 'time') >>> time.dtype dtype('O') >>> time = time.astype(int) >>> time.dtype # doctest: +SKIP dtype('int64')