pandas 1.4.2

ParametersRaisesReturns
maybe_cast_to_integer_array(arr: 'list | np.ndarray', dtype: 'np.dtype', copy: 'bool' = False) -> 'np.ndarray'

Parameters

arr : np.ndarray or list

The array to cast.

dtype : np.dtype

The integer dtype to cast the array to.

copy: bool, default False :

Whether to make a copy of the array before returning.

Raises

OverflowError : the dtype is incompatible with the data
ValueError : loss of precision has occurred during casting

Returns

ndarray

Array of integer or unsigned integer dtype.

Takes any dtype and returns the casted version, raising for when data is incompatible with integer/unsigned integer dtypes.

Examples

If you try to coerce negative values to unsigned integers, it raises:

This example is valid syntax, but we were not able to check execution
>>> pd.Series([-1], dtype="uint64")
Traceback (most recent call last):
    ...
OverflowError: Trying to coerce negative values to unsigned integers

Also, if you try to coerce float values to integers, it raises:

This example is valid syntax, but we were not able to check execution
>>> pd.Series([1, 2, 3.5], dtype="int64")
Traceback (most recent call last):
    ...
ValueError: Trying to coerce float values to integers
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/dtypes/cast.py#1985
type: <class 'function'>
Commit: