numpy 2.0.0
src/multiarray/convert_datatype.h File Reference

Go to the source code of this file.

Functions

NPY_NO_EXPORT
PyArray_VectorUnaryFunc
PyArray_GetCastFunc (PyArray_Descr *descr, int type_num)
NPY_NO_EXPORT int PyArray_ObjectType (PyObject *op, int minimum_type)
NPY_NO_EXPORT PyArrayObject ** PyArray_ConvertToCommonType (PyObject *op, int *retn)
NPY_NO_EXPORT int PyArray_ValidType (int type)
NPY_NO_EXPORT void PyArray_AdaptFlexibleDType (PyObject *data_obj, PyArray_Descr *data_dtype, PyArray_Descr **flex_dtype)

Function Documentation

NPY_NO_EXPORT void PyArray_AdaptFlexibleDType ( PyObject *  data_obj,
PyArray_Descr data_dtype,
PyArray_Descr **  flex_dtype 
)
This function calls Py_DECREF on flex_dtype, and replaces it with a new dtype that has been adapted based on the values in data_dtype and data_obj. If the flex_dtype is not flexible, it leaves it as is.
The current flexible dtypes include NPY_STRING, NPY_UNICODE, NPY_VOID, and NPY_DATETIME with generic units.
This function calls Py_DECREF on flex_dtype, and replaces it with a new dtype that has been adapted based on the values in data_dtype and data_obj. If the flex_dtype is not flexible, it leaves it as is.
Usually, if data_obj is not an array, dtype should be the result given by the PyArray_GetArrayParamsFromObject function.
The data_obj may be NULL if just a dtype is is known for the source.
If *flex_dtype is NULL, returns immediately, without setting an exception. This basically assumes an error was already set previously.

System Message: WARNING/2 (<string>, line 10); backlink Inline emphasis start-string without end-string.
The current flexible dtypes include NPY_STRING, NPY_UNICODE, NPY_VOID, and NPY_DATETIME with generic units.

Flexible types with expandable size
First replace the flex dtype
Get a string-size estimate of the input. These are generallly the size needed, rounded up to a multiple of eight.
Flexible type with generic time unit that adapts
Detect the unit from the input's data

Referenced by get_nbo_datetime_to_string_transfer_function(), and PyArray_CastToType().

NPY_NO_EXPORT PyArrayObject** PyArray_ConvertToCommonType ( PyObject *  op,
int *  retn 
)
Raises error when len(op) == 0

all scalars
we need to upconvert to type that handles both intype and stype also don't forcecast the scalars.
Make sure all arrays are actual array objects.
forcecast scalars

NPY_NO_EXPORT PyArray_VectorUnaryFunc* PyArray_GetCastFunc ( PyArray_Descr descr,
int  type_num 
)
Get a cast function to cast from the input descriptor to the
output type_number (must be a registered data-type). Returns NULL if un-successful.

References PyArray_ArrFuncs::castdict, _PyArray_Descr::f, NpyCapsule_AsVoidPtr(), and NpyCapsule_Check().

NPY_NO_EXPORT int PyArray_ObjectType ( PyObject *  op,
int  minimum_type 
)
End deprecated
Return the typecode of the array a Python object would be converted to

Referenced by new_array_for_sum().

NPY_NO_EXPORT int PyArray_ValidType ( int  type)
Is the typenum valid?